Hello, I am in a required algorithms course where the prof expects everyone to a
ID: 3620299 • Letter: H
Question
Hello, I am in a required algorithms course where the prof expects everyone to already be good in C (which only very few actually are...), so his assignments are harder than most of us can handle...this question is from an assignment that was due last Thursday.Here's the question:
There is a text file with multiple lines of city names. However, before the actual city name, there are some extra letters and than three characters like "/>
ex) torontoon"/>Toronto, Ontario
I want to delete all the characters up to the ">" character so that the line just says "Toronto, Ontario"
I've spent many hours over the last few days trying to write code that could do this. I've found ways to delete substrings of a certain length, but that is not helpful because each line has initial substrings of different lengths.
If any of you have any ideas of how to scan through a string up to a certain character and than how to delete that substring, please let me know.
Thanks for your help.
Explanation / Answer
please rate - thanks didn't know if you could use the string library, so I didn't #include <stdio.h>#include <conio.h>
int main()
{char input[80],city[80];
char instring;
int i,j,k;
FILE *in;
in = fopen("citynames.txt","r");
if(in == NULL)
{ printf("Error opening input file! ");
return 0;
}
while(instring=fgets(input,80,in)>0)
{printf("as input: %s",input);
for(i=0;input[i]!='>';i++);
k=0;
for(j=i+1;input[j]!='';j++)
input[k++]=input[j];
input[k]='';
printf("after"junk" removed: %s ",input);
}
fclose(input);
getch();
return 0;
}
Related 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.