Saturday, May 9, 2009

Need help in C++ file concepts?

One file is having:


name= xx


age=yy


location=zzz





if i give input as name it should print xx


if i give input as age it should print yy and so on..





like the above if i give any key words(name, age,...) it should give the corresponding initialized value from the given file..





i want C++ program for obtaining the above. I'm not familiar with C++ file concepts..so pls provide program for the above


thank you

Need help in C++ file concepts?
First create a file "check.txt" which contains the operands and their corresponding codes(seperated by a tab...)...


(eg)


name xx


age yy


location zzz





save the file in your "bin" folder which is in your c++ software location... then run this code below...





if you have any doubts regarding data structures, oops concepts, assembler coding, microprocessor programming, microcontroller programming, java programming, mail me...


jeganshunmugavel@yahoo.com














code:








#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


#include%26lt;conio.h%26gt;








void search(char temp[])


{


FILE *check;


char ope[10],code[10];


strcpy(code,"");


check=fopen("check.txt","r");


fscanf(check,"%s\t%s",ope,code); //code[strlen(code)-2]='\0';


for(;strcmp(ope,"NULL");)


{


if(strcmp(ope,temp)==0)


{


fclose(check); printf("%s\n",code);


return;


}


fscanf(check,"%s\t%s",ope,code);


}


fclose(check);


printf("\nNOT FOUND");


return;


}





int main()


{


char temp[10],another='y';


while(another=='y')


{


printf("\nEnter your operand: ");


scanf("%s",temp);


search(temp);


printf("\nAnother?");


another=getch(); fflush(stdin);


}


return 0;


}
Reply:u want someone to write program for you :-)





write it urself and if have any error then ask for resolution of error.


or send me the prog i'll solve it for u.





U can get many such sample programs in any c++ book.


No comments:

Post a Comment