Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ C
hi
I'm looking forward to finding the best solution for separation of integer,string and char.
 
char line[100];
gets(line);
 
user input 'there is a 1 room and 90 people'
then the program classifies like below and print them
integer = 1, 90
string = there is room and people'
char = a

I think it's possible to do it with using ascii code, but it has been still confusing.
How to solve it? need your advice
Posted 22-Mar-13 8:57am
kyleK89363
Comments
ThePhantomUpvoter at 22-Mar-13 14:04pm
   
Tokenize the string. The results that contain a single character is a char (according to your statement), the elements that are digits must be integers, right?, then the rest must be strings.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It looks like you want a form of parser or at least a lexer. You can do this sort of thing with Flex and Bison which are free and easy to find with Google.
 
Yes all characters are of course stored as numbers in a computer and one of the most important mappings from numbers to characters is ASCII.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 22 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100