What should be in the Missing Line in the following C Code for it to display the code of itself.#include<string.h>#include<stdio.h>void main(){int pos=0;char c;FILE *fp;--------------- Missing Line-------------if (fp==NULL) {printf("Unable to open\n");return ; }while((c=fgetc(fp))!= EOF) {printf("%c",c); }fclose(fp);}Select one:fp = fopen("selfcode.c");*fp = fopen("selfcode.c","w");None of thesefp = fopen("selfcode.c","r");*fp = fopen("selfcode.c","r");
Question
What should be in the Missing Line in the following C Code for it to display the code of itself.#include<string.h>#include<stdio.h>void main(){int pos=0;char c;FILE *fp;--------------- Missing Line-------------if (fp==NULL) {printf("Unable to open\n");return ; }while((c=fgetc(fp))!= EOF) {printf("%c",c); }fclose(fp);}Select one:fp = fopen("selfcode.c");*fp = fopen("selfcode.c","w");None of thesefp = fopen("selfcode.c","r");*fp = fopen("selfcode.c","r");
Solution
The correct line to fill in the missing code would be:
fp = fopen("selfcode.c","r");
This line of code opens the file "selfcode.c" in read mode and assigns the file pointer to fp. The "r" in the fopen function stands for "read", which means the file is opened for reading.
Similar Questions
What should be in the Missing Line in the following C Code for it to display the code of itself.#include<string.h>#include<stdio.h>void main(){int pos=0;char c;FILE *fp;--------------- Missing Line-------------if (fp==NULL) {printf("Unable to open\n");return ; }while((c=fgetc(fp))!= EOF) {printf("%c",c); }fclose(fp);}Select one:fp = fopen("selfcode.c");*fp = fopen("selfcode.c","w");None of thesefp = fopen("selfcode.c","r");*fp = fopen("selfcode.c","r");
What will be the output of the following C code?
The following code gives this incorrect output.Which of the following statements about what is causing the error is true? (select all valid answers)carrie@ubuntu:/debugging$ cat main.c #include <stdio.h> /** * main - debugging example * Return: 0 */ int main(void) { int i; int j; for (i = 0; i < 10; i++) { j = 0; while (j < 10) { printf("%d", j); } printf("\n"); } return (0); } carrie@ubuntu:/debugging$carrie@ubuntu:/debugging$ gcc -Wall -Werror -Wextra -pedantic main.c carrie@ubuntu:/debugging$ ./a.out0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 <...>^Ccarrie@ubuntu:/debugging$j never increments so it will always be less than 10j never increments so it is always going to print 0j is always equal to i so the loop will never endI don't know
Suppose that in a C program snippet, followings statements are used
What will be the output of the program ?#include<stdio.h>int main(){printf("Code", "Quiz\n");return 0;}AErrorBCodeCCode QuizDQuiz
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.