Tuesday, July 14, 2009

C Programming Experts! HELP!!!??

Is this code right to recieve a text file from the specified location?? I have the code to send the file working properly.





/* Filerecive.c * * * * * * * * * * * * * * * * * * * * * * * * * */


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


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


#define CNTRLZ 0x1A


int main(void) {


FILE * fp;


FILE * dp;


int c;


if ((fp = fopen("C:\\TEMP\\text.txt", "r")) == NULL) {


printf("fail to open data file\n"); return 1;


}


if ((dp = fopen("COM2", "r")) == NULL) {


printf("fail to open COM port\n"); return 1;


}


while ((c = fgetc(fp )) != EOF) {


fputc( c, dp);


}


fputc(CNTRLZ, dp);


fflush(dp);


fclose(fp);


return 0;


}

C Programming Experts! HELP!!!??
hello,





can u paraphrase your question? is this for receiving data from a port and saving to a file or are u telling us there is a problem with the file opening part but the send data by com is working?





Anyways, .... i am not so sure with my answer but :


1. fopen("C:\\TEMP\\text.txt", "r") -%26gt; fopen("C:\\TEMP\text.txt", "r")





if this is for saving the data from a port it should be :


1. fopen("C:\\TEMP\\text.txt", "w+")


2. while ((c) != EOF) {


c = fgetc(dp); /* get from port */


fputc( c, fp); /* write to the file */


}


3. also try to add : fflush(fp) just before close :)





I hope u can clear out your question so we can help u better. good luck and merry christmas in advance.





=)
Reply:hello,





Just post away here on yahoo answers, i think many experts are here in yahoo answers, so they too can help u out =). Whenever time permits, I will check your questions out as soon as I can and assist you. I apologize sincerely for not giving out my mail.





Thanks and hope I can be of service. Report It


mint

No comments:

Post a Comment