Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- /////////////////////////////////////////
- struct T
- {
- int nLen; // Длина строки
- int nInt;
- int nFloat;
- T()
- {
- nLen = 0;
- nInt = 0;
- nFloat = 0;
- }
- void check_int (char *p);
- void check_float(char *p);
- };
- ///////////////////////////////////////////////
- int main()
- {
- char sz[99] = "123,";
- T t_1;
- t_1.check_int(sz);
- if(t_1.nInt == 1)
- {
- printf("integer\n");
- goto L_01;
- }
- t_1.check_float(sz);
- if(t_1.nFloat == 1)
- {
- printf("it is float\n");
- goto L_01;
- }
- printf("it is C-string\n");
- L_01: return 0;
- }
- ////////////////////////////////////////////////
- void T::check_int(char *p)
- {
- nLen = strlen(p);
- int nF = 1;
- for(int i = 0; i < nLen; i++)
- {
- if(p[i] < 48 || p[i] > 57) nF = 0;
- }
- if(nF == 1) nInt = 1;
- }
- ////////////////////////////////////////////////
- void T::check_float(char *p)
- {
- int nPoint = 0;
- for(int i = 0; i < nLen; i++)
- {
- if(p[i] == 44) nPoint ++;
- }
- if(nPoint == 1) nFloat = 1;
- else return;
- int nF = 1;
- for(int i = 0; i < nLen; i++)
- {
- if((p[i] < 48 || p[i] > 57) && p[i] != 44) nF = 0;
- }
- if(nF != 1) nFloat = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment