Thread: Assignment HELP!!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by vart View Post
    fgetc returns int, so using char to store the result even before you are sure it could be stored there -just asking for troubles.
    On compiler where char is unsigned - you'll be unable to determine the EOF condition
    Yes, very true, I will change this in the previous post!
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  2. #2
    Registered User
    Join Date
    Nov 2008
    Posts
    31
    how do i read the string in using fscanf ?
    how do i pass my char array to the first function if i have it in main.

    Code:
    # include<stdio.h>
    
    int main(void)
    {
       # include<stdio.h>
    
    int main(void)
    {
        int numlines;
        char stringline[200];
        
        FILE *fin;
        fin = fopen("bigint.txt","r");
        fscanf(fin, "%d", &numlines); //Read in how many lines there are
        fscanf(fin, "%s", &stringline);
        printf("stringline = %d\n", stringline);
        printf("%d\n", numlines);
        
        fclose(fin);
        system("PAUSE");
        return 0;
    }
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 02:34 AM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  5. Replies: 1
    Last Post: 10-27-2006, 01:21 PM