Question

I can't get the program to read from prospect.csv file and produce the correct prospect_clean.csv file....

I can't get the program to read from prospect.csv file and produce the correct prospect_clean.csv file. Can you help with explanation to the answer?

Project 15-3: File Cleaner

Create an application that reads a file that contains an email list, reformats the data, and writes the cleaned list to another file.

Console

File Cleaner

Source file:  prospects.csv

Cleaned file: prospects_clean.csv

Congratulations! Your file has been cleaned!

The prospect.csv file

FIRST,LAST,EMAIL

james,butler,[email protected]

Josephine,Darakjy,[email protected]

ART,VENERE,[email protected]

...

The prospect_clean.csv file

First,Last,email

James,Butler,[email protected]

Josephine,Darakjy,[email protected]

Art,Venere,[email protected]

...

Specifications

Your instructor should provide a CSV file named prospects.csv that contains a list of prospects.

Your application should fix the formatting problems and write a file named prospects_clean.csv.

All names should use title case (an initial capital letter with the rest lowercase).

All email addresses should be lowercase.

All extra spaces at the start or end of a string should be removed.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>
#include<ctype.h>
int main(int argc, char **argv)
{
   int i,space_count,column_count,letter_position,line_count;
   char container,pre_container;
   FILE *input,*output;

  
   pre_container = 'a';
   input=fopen("prospects.csv","r");
   if(input == NULL)
   {
       printf("\n\t Error in reading file\n");
       return 1;
   }  

   output=fopen("prospects_clean.csv","w");
   if(output == NULL)
   {
       printf("\n\t Error in writing file\n");
       return 1;
   }  
  
   space_count=0;
   column_count=1;
   letter_position=0;
   line_count = 0;
   fscanf(input,"%c",&container);
   while(container != EOF)
   {
       if((container==' ')||(container=='\t'))
       {
           space_count++;
           line_count=0;
       }
       else if(container ==',')
       {
           space_count = 0;
           column_count++;
           letter_position = 0;
           line_count = 0;
           fprintf(output,",");
       }
       else if(container=='\n')
       {
           space_count = 0;
           column_count = 1;
           letter_position = 0;
           line_count++;
       /*   As end of file differ in each operating system. In my PC, at the end of file I get newline character in scanning */
           if((line_count >= 3)||(pre_container == '\r'))
           {
               fprintf(output,"\r\n");
               break;
           }
           else if(line_count == 1)
               fprintf(output,"\n");
           else
               ;
       }
      
       else if((letter_position==0) && (column_count != 3))
       {
           space_count = 0;
           line_count = 0;
           if(islower(container))
               fprintf(output,"%c",toupper(container));
           else  
               fprintf(output,"%c",container);
           letter_position ++;
       }
       else
       {
           line_count = 0;
           for(i=0;i<space_count;i++)
           {
               fprintf(output," ");
           }
           space_count=0;
           if(isupper(container))
               fprintf(output,"%c",tolower(container));
           else  
               fprintf(output,"%c",container);
           letter_position ++;
       }

      
       pre_container = container;
       fscanf(input,"%c",&container);  
   }
   fclose(input);
   fclose(output);
   printf("\n\tCongratulations! Your file has been cleaned!\n");  
   return 0;
}

==================================================================

==================================================================

==================================================================

prospect.csv

==================================================================

prospect_clean.csv

Add a comment
Know the answer?
Add Answer to:
I can't get the program to read from prospect.csv file and produce the correct prospect_clean.csv file....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT