Answered! Write a C program. Take info from standard input, tokenize…

Write a C program.

Take info from standard input, tokenize

The program should use a table-like 2-D array (ie, an array of strings) to record the inputs. use loop to read inputs (from standard in), one input per line, about the user information in the form of name age wage, where age is an integer literal, and wage is a floating point literal with 1 decimal number. See sample input below store each input string into the current available row of the 2D array, starting from the row 0 create a modified string of the input, and store it in the next row of the 2D array. In the modified version of input, a letters in name are capitalized, age becomes age 10 and wage has 50% increases and is formatted with 2 digits after decimal point continue reading input, until a name xxx is entered after reading all the inputs, output the 2-D array row by row, displaying each original input followed by the modified version of the input. display the current date and time and program name before generating the output, using predefined marcos such as TIME

INCOMPLETE CODE

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define ROWS 20
#define COLUMNS 30

int main(int argc, char *argv[])
{
char input_table[ROWS][COLUMNS];

……
int current_row;

printf(“Enter name age and wage: “);
fgets(input_table[current_row], 30, stdin);   // add a /n

while(….)
{
/* need to ‘tokenize’ the read in line*/
……

}

/* now display the input_table row by row */
….
….

return 0;
}

The program should use a table-like 2-D array (ie, an array of strings’) to record the inputs. use loop to read inputs (from standard in), one input per line, about the user information in the form of name age wage, where age is an integer literal, and wage is a floating point literal with 1 decimal number. See sample input below store each input string into the current available ‘row’ of the 2D array, starting from the row 0 create a modified string of the input, and store it in the next row of the 2D array. In the modified version of input, a letters in name are capitalized, age becomes age 10 and wage has 50% increases and is formatted with 2 digits after decimal point continue reading input, until a name xxx is entered after reading all the inputs, output the 2-D array row by row, displaying each original input followed by the modified version of the input. display the current date and time and program name before generating the output, using predefined marcos such as TIME

Expert Answer

 Please find below the solution for above problem:

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <time.h>
#define ROWS 20
#define COLUMNS 40
int main(void)
{
char input_table[ROWS][COLUMNS];
char temp[40];
char exit[10]=”XXX”;
int current_row=0;
const char delim[2] = ” “;
char *token;
time_t mytime;
mytime = time(NULL);
printf(ctime(&mytime));
printf(“program name : tokenizer.cnn”);
//loop initiated for taking input
while(current_row<=20){

printf(“Enter name age and wage: “);
//copied input in temp variable
fgets(temp, 30, stdin);

int exitstatus=0;
//delimitting the string by space
token = strtok(temp, delim);
int i=0;

char name[40];
int age=0;
float wage=0;
while( token != NULL )
{
if(i==0)
{

strcpy(name,token);
//if name==xxx then breaking the loop
if(strcmp(name,exit)==1)
{
exitstatus=1;
break;
}
}
//modifying age
if(i==1)
{
age=atoi(token);

}
//modifying wage
if(i==2)
{
wage=atof(token);
wage=wage+(wage/2);
}
token = strtok(NULL, delim);
i++;
}
if(exitstatus==1)
break;
//converting to string after modifying
char temp1[10];
char temp2[10];
itoa(age,temp1,10);

snprintf(temp2, 10, “%.2f”, wage);
//concating the string
strcat(name,” “);
strcat(name,temp1);
strcat(name,” “);
strcat(name,temp2);
//saving the string to 2d array
strcpy(input_table[current_row],name);
//increasing the row count
current_row++;

}
//displaying data from array
int j;
for(j=0;j<current_row;j++)
{
printf(“%sn”,input_table[j]);
}

return 0;
}

OUTPUT:

Still stressed from student homework?
Get quality assistance from academic writers!