regarding file handling in C

I have a conf file in my hand:
this is:

YYYY:

1. .......
2. ..........
3...................;

ZZZZ:
1. ..........
2. ..........
3. ................;

now I write an app which takes input YYYY/ZZZZ and search for that and returns the string upto ";" who I do that.

rgds,
arijit_rebacaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
manish_regmiConnect With a Mentor Commented:
There are many, the choice is yours,

fgets()
fread()
read()

etc

regards
Manish regmi
0
 
rajeev_devinCommented:
Post the code that you have done so far !
0
 
manish_regmiCommented:
1) open the file
2) read it in string.
3) use strstr to locate the YYYYY string
4) copy the string from : to ; to another string and return;


regards
Manish regmi
0
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

 
arijit_rebacaAuthor Commented:
with the help of which api i read it in string ? i.e. 2 is it fgets() ?
0
 
arijit_rebacaAuthor Commented:
and also the 4 th... with the help of which API?
0
 
arijit_rebacaAuthor Commented:
and for the 4th one?
0
 
manish_regmiCommented:
the returned pointer from strstr points to the beginning of substring you searched. Now skip the words you searched. copy character by character until you get ';'.

char *ptr;
char *tosearch = {"YYYY:"};

ptr = strstr(whole, tosearch);

ptr += strlen(tosearch);

copy ptr[i] to other variable until you get ;

regards
Manish regmi


0
All Courses

From novice to tech pro — start learning today.