Question

In: Computer Science

Using the C language: In the old days, data was stored on punched cards of 80...

Using the C language:

In the old days, data was stored on punched cards of 80 or 96 columns.

Presume your job is to update a database to include the newly found data in the file punchcard.txt
into a currently used data base. In order to do that, you must read in the data in columnar format
and convert it to comma separated fields so it can be imported.

Using buffered I/O functions (e.g. fopen, fclose, fprintf, fscanf, fread or fwrite, fgets, fgets, etc),
read the columnar data in punchcard.txt into your program. It has the following fields:

   unsigned int user_number 6 columns
   char name 32 columns
   char address 32 columns

Write the data out to a file called import.txt which is of the following CSV format for each line:

   user_number,name,address<carriage return>

If the data in name or address contains a comma, it must be delimited with double quotes around
it. Make sure you remove all extraneous spaces in front of, or behind the data so that the entry in
the import.txt file has no extraneous spaces which is not part of the data. This is often called
"trimming" the data.

punchcard.txt contains...

289383Estefana Lewey 9940 Ohio Drv, 85021
930886Burl Livermore 226 Amherst, 08330
692777Lannie Crisler 8143 Woods Drv, 20901
636915Zena Hoke 82 Roehampton St, 47905
747793Vicente Clevenger 9954 San Carlos St., 55016
238335Lidia Janes 348 Depot Ave, 29576
885386Claire Paladino 587 Front Ave, 32703
760492Leland Stillson 9793 Boston Lane, 08610
516649Wes Althouse 8597 Annadale Drive, 06514
641421Nadia Gard 218 George Street, 29150

Thank you in advance.

Solutions

Expert Solution

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*typedef struct
{
    unsigned int user_no;
    char name[32];
    char address[32];
}record;*/
int main(void)
{
    FILE *fp, *fp1;
    char str[70], buff[7];
    char name[32];
    char address[32];

    unsigned int user_no;
    int a, b;
    fp = fopen("punchcard.txt", "r");
    fp1 = fopen("import.txt", "w");
    while (fgets(str, 70, fp) != NULL)
    {
        /* reading emp no.*/
        printf("%s\n", str);
        for(a = 0; a <6; a++)
        {
            buff[a] = str[a];
        }
        buff[7] = '\0';
        user_no = atoi(buff);
        printf("Emp No.:%u ", user_no);

        /* reading name*/
        a = 6;
        b = 0;
        while(str[a] != ' ')
        {
            name[b] = str[a];
            b++;
            a++;
        }
        name[b] = str[a];
        b++;
        a++;
        while(str[a] != ' ')
        {
            name[b] = str[a];
            b++;
            a++;
        }
        name[b] = '\0';
        printf("Emp name:%s ", name);

        /* reading address*/
        address[0]='"';
        a++;
        b = 1;
        while(str[a] != ',')
        {
            address[b] = str[a];
            b++;
            a++;
        }
        address[b] = '"';
        b++;
        a++;
        while(str[a] != '\0')
        {
            address[b] = str[a];
            b++;
            a++;
        }
        address[b] = '\0';
        printf("Address:%s\n", address);
        fprintf(fp1, "%u,%s,%s\n",user_no, name, address);
    }
    fclose(fp);
    fclose(fp1);
    return 0;
}

The import.txt file attached:


Related Solutions

In the old days, there was a probability of 80% of success in any attempt to...
In the old days, there was a probability of 80% of success in any attempt to make a telephone call. (This often depended on the importance of the person making the call, or the operator’s curiosity.) In six attempted calls, (a) Construct a probability distribution for X = the number of successful calls in six attempts. (b) Find the probability that at least two calls will be made successfully. (c) Find the mean and standard deviation of the distribution.
write code data structure using  c language You will build a system to manage patients’ data in...
write code data structure using  c language You will build a system to manage patients’ data in a hospital. The hospital patient management system stores specific information in the form of health record to keep track of the patients’ data. Your program should read the information from a file called “patients.txt” that should be on the following format : Patient Name#Gender#Date of admission#Date of birth #Illness#Address (City)#Blood type Your program should be able to do the following tasks: Options: 1. Read...
Write a Y86 program in C language that sorts an array of data using Bubble Sort....
Write a Y86 program in C language that sorts an array of data using Bubble Sort. Allow the user to input up to 10 numbers from the keyboard. Sort the array in place (i.e., no need to allocate additional memory for the sorted array). Your program should be a complete one
In C, create a program that displays the minimum and maximum values stored in a data...
In C, create a program that displays the minimum and maximum values stored in a data file "datafile.txt". Use the following function prototype:  void minmaxarray(float value, float *min, float *max);
What are stored-value cards and how they are used in electronic commerce
What are stored-value cards and how they are used in electronic commerce
Mrs. Shimizu is an 80-year-old female admitted to the hospital 9 days ago for treatment of...
Mrs. Shimizu is an 80-year-old female admitted to the hospital 9 days ago for treatment of cirrhosis of the liver. On admission she was placed in a semiprivate room with a roommate with kidney failure. Because of her age, she has a compromised immune system and has begun to show signs, by auscultation and radiograph, of lung infiltrate. Physical therapy services, specifically respiratory care, and bed mobility have been ordered for Mrs. Shimizu. 2.What infection-control guidelines should be followed in...
Your goal is to collect all 80 player cards in a game. The Player cards are...
Your goal is to collect all 80 player cards in a game. The Player cards are numbered 1 through 80. High numbered cards are rarer/more valuable than lower numbered cards. Albert has a lot of money to spend and loves the game. So every day he buys a pack for $100. Inside each pack, there is a random card. The probability of getting the n-th card is c(1.05)-n, For some constant c. Albert buys his first pack on June 1st....
Using c programming language How do you put data from a text file into a 2d...
Using c programming language How do you put data from a text file into a 2d array For example a text file with names and age: john 65 sam 34 joe 35 sarah 19 jason 18 max 14 kevin 50 pam 17 bailey 38 one 2d array should have all the names from the file and one 2d array should have all the ages and both arrays should be printed out separately and be 3x3
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot...
Write code in C language in the Arduino IDE ADC data using Serial plotter Serial plot : raw data, delay data (int) Purpose: Delay Block (**Using Class**) Input : u(t) Output : o(t)=u(t-h) sample time=0.02 Delay (h) = 0.4
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT