Sponsored Content
Full Discussion: Wierd C program. Help Needed
Top Forums Programming Wierd C program. Help Needed Post 302145385 by karthikb23 on Wednesday 14th of November 2007 04:28:05 AM
Old 11-14-2007
Wierd C program. Help Needed

Hi,
Please see this:
When i make a declaration as:

char *i, j[15], *k;
and then do
sprintf( k, "print.sh %s", i );

the program works fine.

But when i change the declaration to:
char *i, *k;
and then do
sprintf( k, "print.sh %s", i );
I get a segmentation fault at the 'sprintf' statement.

The program works only when j is an array of 15. Nothing less/more Smilie

Please Note: variable j is just a dummy. I do absolutely nothing with it.
Also, i know using sprintf the way i have done is illegal. The pointer is not assigned to anything, prior to such a statement.

It may be silly Smilie but could someone please explain why this happens? Guess something to do with the way memory is allocated.

Thanks in advance!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Wierd Message????

I am getting this message when I run my script. $ runscript.sh Not connected to any service! Here is the beginning of the script: # 1 - failure # # variable declaration FILEDATE=`date +"%Y%m%d"` Not connected to any service! Right after the FILEDATE gets loaded I get that... (6 Replies)
Discussion started by: lesstjm
6 Replies

2. Programming

Wierd pipe problem

I have encountered a strange problem dealing with pipes and forking. The program basicaly does this: cat file | tbl | eqn | groff Now, I have a parent process that forks children that that exec the stuff that they should. The pipes defined in the parent are the ones used. The chain goes... (1 Reply)
Discussion started by: denoir
1 Replies

3. Solaris

wierd sparc 5

Hi! I own a sparc 5 and i seem to have a strange problem. When its off, it starts by itself... Sounds a bit strange? Iknow. Does anyone know whats causing this?? Could it be the network card? or is it someting in ENV or some other configuration?? //dOzY (5 Replies)
Discussion started by: dozy
5 Replies

4. UNIX for Dummies Questions & Answers

Wierd networking issue

I have Debian Etch release as a fresh install on a PIII to be a router/firewall. I've configured networking, and utilized Shorewall to set up iptables scripting. I've installed dhcp3, both client and server, to pull an ip from my broadband cable modem, and dish out ip's to a switch for other... (2 Replies)
Discussion started by: pflink
2 Replies

5. Programming

Help needed regarding c program

Hi, Currently, i have an application that does logging of messages into a text file and i record the timing for the messages in a format. However, i need to log the messages up to millisec level and the struct tm i am using now only support up to sec, is there any other way to get millisec? ... (2 Replies)
Discussion started by: dwgi32
2 Replies

6. UNIX for Advanced & Expert Users

Which Base Level Filesets needed by a specific program?

hello... thats a great forum btw :) my problem is that I need a list of the Base Level Filesets (BLF) which are needed by a specific program. Is there any command/tool which shows me that? during the installation I can choose "Preview only" so that I can see what BLF´s are missing etc but... (4 Replies)
Discussion started by: cypher82
4 Replies

7. UNIX for Dummies Questions & Answers

Help needed to run simple java program in linux

Hi guys , This is the first time i m running java application inside linux. i have installed jdk-6u20-linux-i586-rpm.bin jre-6u20-linux-i586-rpm.bin in my linux machine. and set JAVA_HOME and JRE_HOME variables respectively. # echo $JAVA_HOME /usr/java/jdk1.6.0_20/ # echo $JRE_HOME... (6 Replies)
Discussion started by: pinga123
6 Replies

8. Debian

Change the privileges needed to run a program

Hi everyone, I have an issue with a project of mine. I have to run a program on a terminal which requires to be logged in as su to have it run it. Given that I'm having problem to use expect to give the password I'd like to change the privilege of that program from SU to normal user ( I have the SU... (13 Replies)
Discussion started by: gaisselick87
13 Replies

9. Programming

Wrapper for unix program - urgent help needed

Hello all , i need some help asap i have a program that keeps killing the machine when i did google searches and 2 days later i ran strace it seems the programm keeps making a system call to gettimeofday to i guess increment a counter ? gettimeofday({1347986584, 464904}, NULL) = 0... (6 Replies)
Discussion started by: NetworkLearning
6 Replies

10. Homework & Coursework Questions

C++ Environment needed on Solaris,Program lifecycle

Hello, I would like to build some sample C++ application on Solaris SunOS 5.8 Generic Virtual sun4v sparc. so I would like to know what are the compilation utilities and runtime utilities I need to get in my machine and will any one explain me the detaied life cycle of program like what... (1 Reply)
Discussion started by: Revathi R
1 Replies
STACK(5)							File Formats Manual							  STACK(5)

NAME
stack - 2.10BSD PDP-11 C stack frame conventions DESCRIPTION
The standard C stack frame layout: ------------------ |...nth argument | push arguments in reverse order ------------------ |second argument | ------------------ | first argument | ------------------ JSR PC,*$_FOO | return address | ------------------ JSR R5,CSV | old R5 value | <----- ------------------ | |previous overlay| | | number | | ------------------ | | r4 | | ------------------ | | r3 | | ------------------ | | r2 | | ------------------ | | first local var| | This is the top of the stack ------------------ | when the called routine ``starts'' | routine | | | allocates | | | storage | | SUB $n,SP | temporary | | ------------------ | | push arguments | | | of next routine| | ------------------ | JSR PC,*$_BAR | return address | | ------------------ | JSR R5,CSV | old R5 value---+------- ------------------ ^ |previous overlay| | | number | | ------------------ | | r4/43/r2/... | | ------------------ | and so on..... | The stack pushes downward through memory addresses. Overlay numbers saved in non-overlaid objects are always zero, but the simplification of not having to maintain two different stack frame formats more than outweighs the extra few micro seconds (less than four) necessary to save the zero ... Functions returning integers leave their return value in R0; functions returning floating constants use FR0; functions returning longs leave return values in R1/R0 (R0 high word, R1 low); functions returning structures leave a pointer to bss storage (one chunk of which is allocated for each such routine) in R0, and the caller will copy from that bss storage to the local destination. Local variables are allocated in such a way that they are referred to as ``-N(R5)'', arguments are referred to as ``+N(R5)''; arguments start at 4(R5), the first integer local declared will be at -10(R5). The SP normally points at the first word available for parameter pushing. A function taking only single word as a parameter can be called simply by moving the parameter into (SP) and calling the function, without having to clean the parameter off the stack on return. Any parameters passed after the first (actually "Nth") must be pushed before the call and cleaned off afterwards. If the function has no local variables and calls no functions, it will allocate no stack and the word labelled ``first local var'' will be unused. It is important to note that routines know how many arguments they pass to a function, and will adjust the stack accordingly after a func- tion returns. NOTE
This stack frame format is the same as that used by overlaid objects in 2.9BSD. AUTHOR
John F. Woods, MIT Concouse Computer Center 3rd Berkeley Distribution STACK(5)
All times are GMT -4. The time now is 11:15 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy