Don't know why C program esgfaults after get opt()?
Hi
This is, i think, the relevant part of my C program that segfaults straight after processing options: Code:
char *usr_nam=0; Code:
Host is localhost Please could someone let me know or help me regarding why this programming is segfaulting on the printf statement following the option processing code? Thankx in advance for any help/replies! |
I don't see how you have concluded the seg fault occurs there.
I would put a \n at the end of the string "We are here" before I would conclude the seg fault was not somewhere far past that point. Without the \n, the text is buffered. |
I put the \n in the printf statement. I also put this after it:
Code:
if(signal(SIGPIPE, SIG_IGN) == SIG_ERR) output: Code:
Starting getopt: Code:
char *cp; |
Quote:
|
I would recommend you always to run the program through valgrind or similar, that is usually really helpful unless you mix e.g. C and Fortran. Furthermore, you have left out the declaration of hints as well. But finally you should allocate space for usr_nam and host an fill these using strcpy or sprintf.
|
Quote:
|
I made sockfd a global variable, instead of a member of a global struct. I also put \n in all the printf()s. After this the program progresses a lot further. Just a few more things to fix. Thank you very much for all the replies. Yes i will run it through GDB(i usually do this as a last resort)
Thankx very much |
All times are GMT -5. The time now is 10:40 AM. |