Here I want you to be able to read a file which has titles of magazine articles
ID: 3642433 • Letter: H
Question
Here I want you to be able to read a file which has titles of magazine articles and the page number they occur on in it.I want you to ask the user for a page number, and give them the article which appears on that page number.
For example.
example.txt
10 The First Article
24 The Article After the first article
33 The Third Article
40 The Forth Article
54 The Last Article
program
>> Enter a page number
24
>> "The Article After the first article" starts on that page number
program
>> Enter a page number
65
>> No Article starts on that page number
The Attached file does not solve the problem, but it will print the entire table of contents for the first list, You can change the name of the file to see it print the table contents for the second list.
.
-----------------------------------
first file attached.txt
04 Ethics for Engineers
06 Ruzyllo on Transistor (r)evolution and its multidisciplinary nature
08 Bird in the hand: An electronic field guide app for bird watchers
15 Single-event soft errors in CMOS logic
23 A pseudo-divide-by-carrier coherent demodulator for DSB-SC signals
28 Data management and synchronization in a mobile ad hoc network
31 Using stereo vision to construct 3-D surface models
38 An eye on visual sensor networks
44 My first job: Engineering evolution
-------------------------------------------
second file attached.c
#include<stdio.h>
int main()
{
char Buffer[128];
FILE* TheFile = fopen("IEEESpectrumArticlesFeb2012.txt","r");
if(TheFile)
{
printf("We were able to open it");
while(fgets(Buffer,128,TheFile)!=NULL)
{
printf("%s ",Buffer);
}
}
else
{
printf("We were not able to open it");
}
return 0;
}
Explanation / Answer
#include #include #include #define MAX 500 //maximum articles in the magazine typedef char * string; struct magazine { int page_no; char article[MAX]; } ; int main() { FILE *ipf,*opf; int i=0,temp,j,t=0; magazine array[100]; string temp_string; temp_string=(string)malloc(100*sizeof(char)); ipf=fopen("input.txt","r"); if(ipf==NULL) { printf("Cannot read from the file "); exit(1); } else { while(iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.