WRITE A CODE IN C TO SEARCH A FILE FROM NOTEPAD FILE.
Answer / Somdutta Singh
Here's a simple example of C code to search for a specific string within a .txt file using the fopen(), fread(), and strstr() functions. Note that this code assumes that the file is present in the current working directory:
1. #include <stdio.h>
2. #include <string.h>
3. int main(int argc, char *argv[]) {
4. FILE *file;
5. char filename[] = "example.txt";
6. char line[100];
7. char target[] = "keyword"; // replace 'keyword' with your search term
8. if ((file = fopen(filename, "r")) != NULL) {
9. while (fgets(line, sizeof(line), file) != NULL) {
10. if (strstr(line, target) != NULL) {
11. printf("Found the keyword in the file.n");
12. break;
}
}
13. fclose(file);
14. } else {
15. printf("Unable to open the file.n");
16. }
17. return 0;
18. }
| Is This Answer Correct ? | 0 Yes | 0 No |
write a program of bubble sort using pointer?
What is the difference between exit() and _exit() function?
main() { char *p; p="Hello"; printf("%c\n",*&*p); }
Why & is used in scanf in c?
ABCDCBA ABC CBA AB BA A A
Write a Program to accept different goods with the number, price and date of purchase and display them
Describe newline escape sequence with a sample program?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
what is the difference between call by value and call by reference?
5 Answers Genpact, Global Logic, Infosys,
Explain Linker and Loader
why use functions a) writing functions avoids rewriting the same code over and over b) using functions it becomes easier to write programs and keep track of what they are doing c) a & b d) none of the above
Do you know the use of 'auto' keyword?