for example:
{
printf("\t\t\tCUBE");
printf("\nEnter the side: ");
scanf("%lf", %26amp;side);
printf("\nThe volume of the cube: %.2lf unit cube", side * side * side);
}//cube
I want the user to choose that he or she want to show the soluiton.
and the solution is put it in the text file then the user want to show the solution it will appear.
example:
//output
want to show the solution?(y/n)
y
side^3 = answer
please help me with my problem. thanks. Ü
What is the code in C programs when using a text file for the output?
If you want the output to come from a file, you need to open a File pointer, associate a filename with the pointer, and then explicitly send output from this file ptr. For example, let's say the program prompt the user to enter the name of a file to get the answer from, then you could do:
#define MAX 80
FILE * answer_file;
char words[MAX];
if((answer_file = fopen(argv[1], "r")) == NULL {
fprintf(stderr, "Error opening %s\n", argv[1]);
exit(1);
}
Then you can do something like this to output from a file:
while (fgets(words, MAX, output) != NULL %26amp;%26amp; words[0] != '\n')
fputs(words, stdout);
Reply:// this is one way to write to file
FILE * fp;
if (fopen( fp, "myTextFileName", "w" ) != NULL)
{
fprintf( fp, "\nThe Volume: %lf cube", s*s*s);
fclose(fp);
}
// hope this helps
Reply:- char y="y";
- char n="n";
- char solution;
printf("\t\t\tCUBE");
printf("\nEnter the side: ");
scanf("%lf", %26amp;side);
- printf ("\n Want to show the Solution ? (y/n): );
- scanf ("%s",solution);
- if (solution==y) continue; else break;
printf("\nThe volume of the cube: %.2lf unit cube", side * side * side);
Should be like this there is no c compiler in my pc can be lil wrong spellings but should be like this. I hope it help
Reply:there is not such commad in c
you can do so by using printf statement
see the below attachment
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment