Parsing Text File and gathering input variables

This is a discussion on Parsing Text File and gathering input variables within the C Programming forums, part of the General Programming Boards category; Hi, I have a text file which contains some text. Now I want to get the some variables out of ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    13

    Parsing Text File and gathering input variables

    Hi,

    I have a text file which contains some text. Now I want to get the some variables out of the TextFiles.

    The format of the file is something like this:

    MyVariables

    a,b,c,d

    .....
    ....
    ...
    end


    So now I want to parse the text file and get a,b,c,d into a array or a queue or stack (some sort of collection).

    At this point I am able to read the file using the following code:

    Code:
    int main() {
        
    
    	FILE *fp;
        char name[25];
        char buff[BUFSIZ];
        float num;
    
    	char ch; 
        
        if((fp=fopen("AboutMe.txt","r"))==NULL)  
        {
            perror("File cannot be opened");
            getchar();
         }
        
    
    	while((ch = fgetc(fp)) != EOF)
    	 {	
    		if(ch == 13) 
    			printf("Line break has been found"); 
    				
    		
    		printf("%c",ch); 		 	
    	 }
      
        getchar();
        return 0;

    Thanks,

  2. #2
    Learner Axel's Avatar
    Join Date
    Aug 2005
    Posts
    335
    read it line by line with sscanf and store it in a array

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    13
    Thanks Axel. I will try that !!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gathering input as array
    By twans in forum C Programming
    Replies: 4
    Last Post: 12-12-2001, 11:27 AM
  2. Help!!!!!!!!
    By Shy_girl_311 in forum C++ Programming
    Replies: 3
    Last Post: 10-10-2001, 03:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21