| | |
parsing with sscanf
![]() |
•
•
Join Date: Mar 2006
Posts: 131
Reputation:
Solved Threads: 0
I'm having trouble parsing a line with sscanf.
My line is:
1941 How Green Was My Valley; John Ford
and I want to separate it into a number, string, and another string. I tried:
But the separation doesn't work the way I want it to.
My line is:
1941 How Green Was My Valley; John Ford
and I want to separate it into a number, string, and another string. I tried:
C Syntax (Toggle Plain Text)
if ( sscanf( buffer, "%d %41[^;] %51s", &pMovie->year, &pMovie->title, &pMovie->director ) == 3 )
But the separation doesn't work the way I want it to.
How about something like:
c Syntax (Toggle Plain Text)
int main(void) { char buffer[] = "1941 How Green Was My Valley; John Ford." ; int year = 0 ; char title[BUFSIZ] = { '\0' } ; char director[BUFSIZ] = { '\0' } ; if ( sscanf( buffer, "%d %[^;]; %[^.]", &year, &title, &director ) == 3 ) printf( "Year = %d, title = %s, diretro = %s", year, title, director ) ; getchar( ) ; }
I don't accept change; I don't deserve to live.
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: area/volume
- Next Thread: How do you create a text file?
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks binarysearch calculate centimeter changingto char character convert copyanyfile copyimagefile copypdffile creafecopyofanytypeoffileinc createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop function getlogicaldrivestrin givemetehcodez grade gtkwinlinux histogram homework i/o ide inches include infiniteloop input interest intmain() iso keyboard km license linked linkedlist linux list looping lowest matrix meter microsoft mysql number oddnumber open opendocumentformat openwebfoundation pdf pointer posix power probleminc process program programming pyramidusingturboccodes radix read recursion recv recvblocked research reversing scheduling segmentationfault send sequential single socket socketprogramming stack standard strchr string suggestions systemcall test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






