[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Function Help...

Posted on 2000-01-19
7
Medium Priority
?
166 Views
Last Modified: 2010-04-15
I need to develop a function that will collect the following information from the user...

Title
Type (action, comedy, etc.)
Actors (up to three)
Status (checked in, checked out)
Out To (name of customer, if checked out)

I am not very good with getting character strings from the user...

Any help?

thanks,

mapper
0
Comment
Question by:mapper
7 Comments
 
LVL 3

Expert Comment

by:luisr
ID: 2369682
Use gets()... it will read a string into a buffer.
0
 
LVL 85

Expert Comment

by:ozo
ID: 2369728
fgets() would be safer
0
 
LVL 2

Expert Comment

by:Slarti
ID: 2370023
Experts are prohibited from answering customers' homework assignments.
0
Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

 
LVL 3

Expert Comment

by:arnond
ID: 2370395
ozo, how about scanf() or fscanf() ?

Arnon David.
0
 
LVL 18

Accepted Solution

by:
deighton earned 200 total points
ID: 2371328
#include<stdio.h>

void ans(char *type,char *act1,char *act2,char *act3,char *stat,char *outto)
{
      printf("Enter Type ");
      gets(type);
      printf("Actor 1 ");
      gets(act1);
      printf("Actor 2 ");
      gets(act2);
      printf("Actor 3 ");
      gets(act3);
      printf("status ");
      gets(stat);
      printf("Out To");
      gets(outto);
}

main()
{
char t[80],a1[80],a2[80],a3[80],s[80],o[80];
ans(t,a1,a2,a3,s,o);
printf("%s %s %s %s %s %s",t,a1,a2,a3,s,o);
getch();
}

0
 

Author Comment

by:mapper
ID: 2371575
deighton,

I had the function part down with the gets - I was a little confused about passing the user info back to the main function.

I will play around with it thanks...

My sone wants to use this for his pokemon collection if I can get it to work...

Thanks,

Mapper
0
 
LVL 18

Expert Comment

by:deighton
ID: 2373636
The way I did it passes a pointer (address in memory) to the beginning of the string
char *name;

when you use the name of a string (character array) without the [] you are giving a pointer to the first byte of the string, so

x is the same as &x[0]
0

Featured Post

Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Suggested Courses

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question