I've been tasked to do 2 questions. I think i got the majority of it done, but i'm having trouble.
Question #1:
Write a C program that accepts as input from the keyboard a floating point number, an integer, and a character. Each of these inputs should be preceded by a prompt and stored using individual variable names. Have your program call a function that assembles the input data into a single string. Display the assembled string using the 'puts()' call back in 'main' after the function has completed.
Here's what i have so far:
#include <stdio.h>
#include <string.h>
int main()
{
#define MSIZE 50
char message[MSIZE];
float number1;
int number2;
char char1;
printf("Please enter a character: ");
scanf("%c", &char1);
printf("Please enter a floating point number: ");
scanf("%f", &number1);
printf("Please enter an integer: ");
scanf("%d", &number2);
gets(message);
printf("The string message is \n");
puts(message);
system("pause");
return 0;
}
I'm trying to get the inputted data together by some how using the 'strcat' function that's why included <string.h>. that way i can "make" a message out of it...
Here's the 2nd Question:
Create a structure that has one variable called 'value' and one pointer to the list (making it a linked list). Prompt for 5 values from the keyboard as input and store them in the linked list. Print out the current contents of the list. Allow the user to add one more 'value' to the linked list, and print the contents of the list again.
Here's what i have so far:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int *value;
value = (int *) malloc(5 * sizeof(int));
for(i = 0; i < 5; i++)
{
printf("Enter a value: ");
scanf("%d", &value[i]);
}
printf("Here are the values you entered into the array so far: \n");
for (i = 0; i < 5; i++)
printf("%d\n", value[i]);
printf("Please enter one more value: ");
scanf("%d");
system("pause");
return 0;
}
i've got the majority of it correct (i think) it's the adding of 1 more value that screws me up. can somebody help me with my questions. thanks
All insights or suggestions are greatly appreciated!.
Thanks for your time in advance :)
-t