Thread: Segmentation fault on printf() [NOOB ALERT]

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    144

    Segmentation fault on printf() [NOOB ALERT]

    Hi, everyone. I'm tearing my hair out. The second printf statement segfaults. Printed on the screen is:

    BeforeLibcurlinitializedsuccessfully
    Segmentation fault

    Code:
    #include "curl/curl.h"		/*        /usr/include/curl/curl.h comes with package libcurl4-dev     */
    #include <stdio.h>
    #include <string.h>
    #include "Error.h"
    
    #define StringMax 100
    
    static unsigned int libcurlinitialized = 0 ;
    
    int initializeinternetfunctions ( void )
    { 
    	char Message2 [] = "Libcurl initialized successfully.\n" ;
    	printf("Before");
    	int z = printf ( "%s" , Message2 ) ;
    	printf("After");
    	if ( z != strlen ( Message2 ) )
    	{
    		ErrorMessage ( "Couldn't print to screen." , __FILE__ , __LINE__ );
    		return -1;
    	}
    
    	return 0 ;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    It's not the second printf that was segfaulting, or you wouldn't see it. It's more likely that it's after it returns. Your "After" doesn't have a newline, which means that printf isn't required to immediately flush (write so you can see it) the output stream. It's probably printing "After", you don't see it, because it immediately crashes after it returns, but before it writes "After".


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    144

    You're right

    Yes, you're right. This code is not where the error is. I'll continue bug hunting.

    Richard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 01-29-2011, 04:54 AM
  2. Newb Help: Full Arrays and Functions
    By LycanGalen in forum C Programming
    Replies: 5
    Last Post: 01-31-2008, 08:35 PM
  3. Segmentation Fault?
    By John_L in forum C Programming
    Replies: 10
    Last Post: 10-02-2007, 08:37 AM
  4. error in program????
    By SpEkTrE in forum C Programming
    Replies: 5
    Last Post: 11-24-2003, 06:16 PM
  5. Drawing tables in C
    By stanoman in forum C Programming
    Replies: 5
    Last Post: 10-09-2003, 10:14 AM

Tags for this Thread