How to read in/write to a file in Eclipse C [message #1869405] |
Thu, 15 August 2024 20:39  |
Eclipse User |
|
|
|
I'm trying to read in data from a txt file into my main file and also to write some function output to a new file but have not had success in doing either.
Currently have these lines, where both pointers are always null, and I don't know why. I tried moving the c_readin file to the eclipse_workspace folder for this project itself, and the pointer was still null.
int main(void)
{
FILE *fptr1 = fopen("c_readin.txt", "r");
if(fptr1 == NULL)
{
printf("Noooooo!");
exit(1);
}
FILE *fptr = fopen("C:/Users/riaprakash/Desktop/ml_output.txt", "w");
if(fptr == NULL)
{
printf("Error!");
exit(1);
}
memcpy(printed_out, ml_data32, sizeof(printed_out));
fprintf(fptr, "%x\n", printed_out[0]);
fclose(fptr);
return 0;
}
|
|
|
Re: How to read in/write to a file in Eclipse C [message #1873076 is a reply to message #1869405] |
Thu, 05 December 2024 12:45  |
Eclipse User |
|
|
|
Your file paths are likely the issue. Use absolute paths for both files to ensure they're correctly located, and check that you have the necessary read/write permissions. Also, replace printf("Error!") with perror to get detailed error messages for easier debugging!
|
|
|
Powered by
FUDForum. Page generated in 0.07774 seconds