C Programming Assignment Objectives: To gain experience in dynamic memory alloca
ID: 3694691 • Letter: C
Question
C Programming Assignment
Objectives: To gain experience in dynamic memory allocation and file processing
Assignment: Write a modularized program that’s reads a file with unknown number of records
Read a file with the following fields: first and last names, address, city, state, and a phone number. All fields are separated by a tab (‘ ’).
Sort records by city and output sorted records to a file
Clearly label the output Well document your code (comments)
NO goto, continue, break (except for switch)
Sample Input:
Mary.......Jones..........6201 Winnetka Ave..........Woodland Hills.............Ca ..................91371................8187196478
(NOTE: THE DOTS ABOVE ARE THE SPACES)
Use adequate test data to test your program. Copy/paste the output into your source code using comments. Be sure your output contains user prompts and what was entered by the user in addition to the results of your program processing.
Explanation / Answer
int sort(char str[50][50]{ // function to sort
int i,j,n;
char str[20][20],temp[20];
puts("Enter the no. of string to be sorted");
scanf("%d",&n);
for(i=0;i<=n;i++)
gets(str[i]);
for(i=0;i<=n;i++)
for(j=i+1;j<=n;j++){
if(strcmp(str[i],str[j])>0){ // swap if miss the order
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
printf("The sorted string "); // printing sorted string with this way can refer another strings name etc to print
for(i=0;i<=n;i++)
puts(str[i]);
return 0;
}
Due to the time, I could not able to finish the program properly. However above may full fill your requirement.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.