-
February 23rd, 2009, 09:59 PM
#1
file manipulation
Hi ,
I have a file that I want to recognize some words (vector names) and then because the whose name represent arrays, I want to extract their values. I don't know exactly how do to it now.
I made this little program but It does nothing but reproducing the file. It was supposed to recognize the word "request" and display "found": it does not do it. Something is wrong with my logic. please can someone help me?
Code:
#include <stdio.h>
#include <string.h>
#include<stdlib.h>
char line[100];
int increment_line;
int c, ch,find,i;
char string1[100]= "request";
char string2[98];
char lines[10];
int main()
{
FILE *fp;
//printf("line number");
fp = fopen( "files.txt", "r" );
if (fp == NULL)
{
printf("Error opening 'files.txt' ... \n");
getchar();
return 1;
}
else printf("file exists\n");
while((ch=fgetc(fp))!=EOF)
{
line[i++]=ch;
while((ch=fgetc(fp))!='\n'&&(ch!=EOF))
{
line[i++]=ch;
}
line[i]='\0';
i=0;
if (ch=='\n'){increment_line+=1;}
find=strcmp( string1, line);
if(find==0)
{ printf(" found %d at line %d\n", find, increment_line);}
printf("\n %s",line);
}// end main while
printf("\n number line: %d", increment_line);
getchar();
fclose( fp );
return 0;
}
the file is like this:
Code:
m:3 /* number of resources */
n:2 /* number of processes */
available[1] = 1
available[2] = 2
available[3] = 4
max[1,1] = 0
max[1,2] = 3
max[1,3] = 2
max[2,1] = 2
max[2,2] = 1
max[2,3] = 1
process_1:
4
2
request(0,1,2)
release(0,1,2)
request(1,0,3)
end.
process_2:
3
5
request(0,1,12)
release(0,1,12)
request(1,3,3)
end
If I can put it in a temporary array, I want to extract the values in the vector request and process them . I would like to do the same for release.
Thank you
Last edited by brad sue; February 24th, 2009 at 02:15 AM.
-
February 24th, 2009, 02:15 AM
#2
-
February 24th, 2009, 08:38 AM
#3
Re: file manipulation
Mark your thread "Resolved" if you dont expect an answer anymore!
Rate the posts which you find useful
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|