C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-25-2005, 10:08 PM   #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,
azamsharp1 is offline   Reply With Quote
Old 10-25-2005, 11:20 PM   #2
Learner
 
Axel's Avatar
 
Join Date: Aug 2005
Posts: 335
read it line by line with sscanf and store it in a array
Axel is offline   Reply With Quote
Old 10-26-2005, 08:43 AM   #3
Registered User
 
Join Date: Oct 2005
Posts: 13
Thanks Axel. I will try that !!
azamsharp1 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
gathering input as array twans C Programming 4 12-12-2001 11:27 AM
Help!!!!!!!! Shy_girl_311 C++ Programming 3 10-10-2001 02:22 PM


All times are GMT -6. The time now is 01:47 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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