| | |
How to put a full sentence into an array?
![]() |
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
I am trying to write a program that will input a bunch of names into an array of structures under the .name heading. Currently I have what is below to get it to work. But it's not very flexible. You have to input both a first and a last name before it will go on. Is there any command similar to cin.getline for C++ that will work in this instance? Or a way to leave last as null if a second ("last") name isnt input that time around?
c Syntax (Toggle Plain Text)
for (count_s=0; count_s < num_stu; count_s++){ printf("\nEnter name of student #%i: ",count_s+1); scanf("%s %s", &first, &last); strcpy(student[count_s].name, first) strcat(student[count_s].name, " "); strcat(student[count_s].name, last); }
0
#2 33 Days Ago
•
•
•
•
I am trying to write a program that will input a bunch of names into an array of structures under the .name heading. Currently I have what is below to get it to work. But it's not very flexible. You have to input both a first and a last name before it will go on. Is there any command similar to cin.getline for C++ that will work in this instance? Or a way to leave last as null if a second ("last") name isnt input that time around?
c Syntax (Toggle Plain Text)
for (count_s=0; count_s < num_stu; count_s++){ printf("\nEnter name of student #%i: ",count_s+1); scanf("%s %s", &first, &last); strcpy(student[count_s].name, first) strcat(student[count_s].name, " "); strcat(student[count_s].name, last); }
1
#3 33 Days Ago
c Syntax (Toggle Plain Text)
fgets( student[count_s].name, sizeof (student[count_s].name), stdin );
![]() |
Other Threads in the C Forum
- Previous Thread: getline error
- Next Thread: Problem with Structs
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile createcopyoffile createprocess() directory dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlasterror getlogicaldrivestrin givemetehcodez grade graphics gtkgcurlcompiling gtkwinlinux hardware highest histogram homework i/o ide inches infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string suggestions test testautomation threads unix urboc user variable whythiscodecausesegmentationfault win32api windows.h windowsapi






