Question

**C programming Language 3) Prompt the user for data points. Data points must be in this...

**C programming Language

3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they have finished entering data points. Output the data points. Store the string components of the data points in an array of strings. Store the integer components of the data points in an array of integers. (4 pts)

Ex: Enter a data point (-1 to stop input): Jane Austen, 6

Data string: Jane Austen

ata integer: 6

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

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int num; //global variable to store numeric valu after comma

//function to check comma present in input string or not
int check_comma(char s[50])
{
int i,pos,count=0;
for(i=0;i<strlen(s);i++)
{
if(s[i]==',')
{
count++;
pos=i;
}
}
if(count==1)
return(pos);
else if(count==0)
return(-1);
else
return(-2);
}

//function to check numeric values present after comma or not
//if yes then store in global variable num
int check_Int(char s[50], int pos)
{
int i;
num=0;
for(i=pos+1;i<strlen(s);i++)
{
if(s[i]>=48 && s[i]<=57)
num=num*10+(s[i]-48);
else
return 0;

}
return 1;
}
int main()
{
char s[50][50], c[50], s1[50],s2[50];
int arr[50],flag=1,i,pos,f,count=0;
while(flag)
{
printf("\n Enter a data point(enter -1 to stop): ");
gets(c);
if(!strcmp(c,"-1"))
flag=0;
else
{
pos=check_comma(c);
if(pos>=0)
{
f=check_Int(c,pos);
if(f)
{
for(i=0;i<pos;i++)
{
s1[i]=c[i];
}
s1[i]='\0';
strcpy(s[count],s1);
arr[count]=num;
printf("\n Data string: %s", s1);
printf("\n Data integer: %d", num);
count++;

//printf("%d", num);
}

else
printf("\n comma not followed by integer.");
}
else if(pos==-1)
printf("\n no comma in the input");
else
printf("\nToo many commas in input");
}

}
/*printf("\nNumbers are: ");
for(i=0;i<count;i++)
{
printf("%d ",arr[i]);

}
printf("\nStrings are: ");
for(i=0;i<count;i++)
{
printf("\n%s ",s[i]);

}*/

}

output:

EAc prog devlstring token.exe Enter a data point (enter -1 to stop): Jaen austin,6 ta string jaen austin Data integer: 6 Ente

Add a comment
Know the answer?
Add Answer to:
**C programming Language 3) Prompt the user for data points. Data points must be in this...
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
  • computer science . the programming language is python

    11.9 LAB*: Program: Data visualization(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they...

  • Program: Data visualization

    5.10 LAB*: Program: Data visualization(1) Prompt the user for a title for data. Output the title. (1 pt)Ex:Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored(2) Prompt the user for the headers of two columns of a table. Output the column headers. (1 pt)Ex:Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels You entered: Number of novels(3) Prompt the user for data points. Data points must be in this format: string, int. Store the information before the comma into a string variable and the information after the comma into an integer. The user will enter -1 when they...

  • Need help with this homework, and follow the bolded text required 7.10 LAB: Data Visualization (1) Write a function, get_data_headers(), to prompt the user for a title, and column headers for a table....

    Need help with this homework, and follow the bolded text required 7.10 LAB: Data Visualization (1) Write a function, get_data_headers(), to prompt the user for a title, and column headers for a table. Return a list of three strings, and print the title, and column headers. (2 pt) Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored Ex: Enter the column 1 header: Author name You entered: Author name Enter the column...

  • In this assignment you are going to handle some basic input operations including validation and manipulation,...

    In this assignment you are going to handle some basic input operations including validation and manipulation, and then some output operations to take some data and format it in a way that's presentable (i.e. readable to human eyes). Functions that you will need to use: getline(istream&, string&) This function allows you to get input for strings, including spaces. It reads characters up to a newline character (for user input, this would be when the "enter" key is pressed). The first...

  • 6.6 Warm up: Parsing strings (Python 3) (1) Prompt the user for a string that contains...

    6.6 Warm up: Parsing strings (Python 3) (1) Prompt the user for a string that contains two strings separated by a comma. (1 pt) Examples of strings that can be accepted: Jill, Allen Jill , Allen Jill,Allen Ex: Enter input string: Jill, Allen (2) Report an error if the input string does not contain a comma. Continue to prompt until a valid string is entered. Note: If the input contains a comma, then assume that the input also contains two...

  • *In Python please***** This program will display some statistics, a table and a histogram of a...

    *In Python please***** This program will display some statistics, a table and a histogram of a set of cities and the population of each city. You will ask the user for all of the information. Using what you learned about incremental development, consider the following approach to create your program: Prompt the user for information about the table. First, ask for the title of this data set by prompting the user for a title for data, and then output the...

  • Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items...

    Write in C# Programming Language.   - count =0; - Create a 2d array "items". string[,] items = new string[100, 4]; - Create a do while loop, when user enter "0", stop the loop. - User enter item name, price, quantity, save these info and subtotal to array. - increase "count++" -conver price(decimal, Convert.ToDecimal() ) and quantity(int) to do mulplication for subtotal - create a for loop (with count ) to cycle through the "items", display item name, price, quantity, and...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • In assembly language computer programming 1. create a 5 element array 2.prompt the user to enter...

    In assembly language computer programming 1. create a 5 element array 2.prompt the user to enter 5 numbers to fill the array 3. exchange the number at position 1 with the number at position 4 of the array. (Don't forget that array positions are counted from zero, in our case 5 element array positions are counted 0,1,2,3,4.) 4.Display the array numbers 1 and 4 to show that you did the exchange correctly. Show a message like "The number at position...

  • use C++ programming language and follow the instruction carefully. thanks! Inputs: . [integer] values (10 times)...

    use C++ programming language and follow the instruction carefully. thanks! Inputs: . [integer] values (10 times) Outputs: • [integer) highest value . [integer] lowest value Description: Write a program that lets the user enter 10 values. These values should be stored in an array. Your program will then find the highest and lowest values in the array. Your program will display the list of number as a comma separated list, and print which values is the highest and lowest Do...

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