New Reply

c language: I cannot find the output file.

 
Share Thread Thread Tools
Aug4-12, 02:30 AM   #1
 

c language: I cannot find the output file.


What is wrong with my code?


Code:
#include <stdio.h>


int
main(int argc, char *argv[])
{
	int i=0;
	FILE *fp;
	char fname[100];

	sprintf(fname,"%04X.txt",i);	
	fp=fopen("fname", "w");
	fprintf(fp, "hello world!\n");
	fclose(fp);
}
 
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Front-row seats to climate change
>> Attacking MRSA with metals from antibacterial clays
>> New formula invented for microscope viewing, substitutes for federally controlled drug
Aug4-12, 03:58 AM   #2
 
Recognitions:
Homework Helper Homework Help
Quote by nenyan View Post
What is wrong with my code?


Code:
#include <stdio.h>


int
main(int argc, char *argv[])
{
	int i=0;
	FILE *fp;
	char fname[100];

	sprintf(fname,"%04X.txt",i);	
	fp=fopen("fname", "w");
	fprintf(fp, "hello world!\n");
	fclose(fp);
}
Hi nenyan!

Can you find a file named "fname" (literally)?
 
Aug4-12, 06:13 AM   #3
 
Or, in order to generate the file with the file name that you are expecting, you need to remove the double-quotes from around "fname" in the open statement so that you use the variable name fname and not the literal string "fname"
 
Aug4-12, 10:23 AM   #4
 

c language: I cannot find the output file.


Quote by I like Serena View Post
Hi nenyan!

Can you find a file named "fname" (literally)?
yes....I can....
 
Aug4-12, 10:23 AM   #5
 
Quote by gsal View Post
Or, in order to generate the file with the file name that you are expecting, you need to remove the double-quotes from around "fname" in the open statement so that you use the variable name fname and not the literal string "fname"
Thank you very much!
 
New Reply
Thread Tools


Similar Threads for: c language: I cannot find the output file.
Thread Forum Replies
Python and file output Engineering, Comp Sci, & Technology Homework 3
Java Program Input from file, output to file(s) Engineering, Comp Sci, & Technology Homework 31
MCNP output file interpretation Nuclear Engineering 3
file output Programming & Comp Sci 4
Fortran output file Programming & Comp Sci 1