| | |
How to put a full sentence into an array?
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 Oct 30th, 2009
•
•
•
•
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 Oct 30th, 2009
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 |
Tag cloud for C
#include adobe ansi array arrays asterisks binarysearch calculate centimeter changingto char convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework getlasterror givemetehcodez grade graphics gtkgcurlcompiling hacking hardware highest histogram inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard multi mysql number opendocumentformat opensource owf pattern pdf performance pointer posix problem probleminc process program programming radix recursion recv repetition research reversing scanf scripting segmentationfault sequential shape socket socketprograming stack standard string strings structures systemcall testing threads turboc unix user variable voidmain() wab windows.h windowsapi






