473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Some Help Please with Strings and Structures

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
Jun 3 '07 #1
2 3935
kky2k
34
I have some questions to ask.In ur first coding example
U r displaying the string message.Fine but where r u copying ur i/p's to that string?

so what does it mean gets(message);?

let me give u one hint to solve that problem..how abt sprintf();

also try to #define outside a fn.

Abt ur second coding...
where is the structure for ur linked list?
U r simply coying the datas into a array not into a linked list..
so in order to create a linked list in C,u gotto know abt structure in C...


Hope this will help u.....
Jun 3 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
First things first. You have a char, int and float. These need to be converted to a string.

So, you have to convert each of these things to a string and then append the strings together to make the message. May be somthing like:

Expand|Select|Wrap|Line Numbers
  1. void MakeMessage(char* the messagearray, float n1, int n2, char n3);
  2.  
Remember, the puts() function requires a string so be sure yours has the \0 terminator.

Call this function in main():

Expand|Select|Wrap|Line Numbers
  1. MakeMessage(message, number1, number2, char1);
  2.  
Doing it this way localizes all the conversion code to the MakeMessage() function.

Get this part working first. Then sunmit a new post for the linked list issue.
Jun 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Uwe Mayer | last post by:
Hi, thanks to previous help my wrapper for an abstract file type with variable record length is working now. I did some test runs and its awfully slow: I didn't want to read in the whole file...
7
by: bearophileHUGS | last post by:
(This is a repost from another python newsgroup). While using some nested data structures, I've seen that I'd like to have a function that tells me if a given data structure contains one or more...
1
by: jr | last post by:
Could some please direct me to the FAQ - thanks? -- --- If you need to reply personally, append "text" to the domain name in my email adr. Thanks
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
1
by: Terrance | last post by:
Hello, I was wondering if someone can help me understand something. Below is some code that I got from the MS website that is suppose to authenticate for the username and password on the local...
8
by: ashu | last post by:
lets take a look at the following code:- #include<stdio.h> #include<conio.h> struct tag{ int age; char *name; }a;
5
by: wendyzhakata | last post by:
you are required to keep tailoring records of fellow students in your class. each record is made up of the following fields: (a)Fname: a character array of maximum15 characters representing the...
1
by: Mani kansal | last post by:
hi, 1. for which statements redo will be generated? 2. and Scn will be generated for DDL'S only or both DDL and DML?
2
by: cephal0n | last post by:
I have this peroblem thats really bugging me for days, please have a patience to read it and help me find the probplem because I knew I missed it and just cant tell where. I have a table named...
4
thatos
by: thatos | last post by:
I would like to import a Jericho HTML Parser which is the the following file E:\project\jericho-html-2.5\ how can I do this I am supposed to write the following import function in my java...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.