| | |
Urgent Strings help!!!
![]() |
•
•
Join Date: Dec 2009
Posts: 2
Reputation:
Solved Threads: 0
hi there.
i have 6 long numbers in a text file that i am reading from.
these numbers can be of any length but written in the one of the formats as i have written below.
the numbers are
102,2131,432 //format 1
32,531 //format1
74 //format2
534532.5 //format3
1,500 //format1
3,120,352 //format1
i want the output as
102
32
74
534532
1
3
. i.e. the numbers before the commas or the dots. i want to discard everything else. Any idea how i can get them???
i have the code to read the file and stuff. i just need the code for this bit.
the output is inside the same while loop that i am using to read the file. the loop is...
while(fscanf(MYFILE,"%s", &STOREHERE) == 1)
{
//my code is here
}
i dont want to put my code here because its a very long and complicated one. n i dont want to confuse all of u by telling u d whole thing. please help me in getting just what i have stated above.
Many thanks in advance,
Tim.
i have 6 long numbers in a text file that i am reading from.
these numbers can be of any length but written in the one of the formats as i have written below.
the numbers are
102,2131,432 //format 1
32,531 //format1
74 //format2
534532.5 //format3
1,500 //format1
3,120,352 //format1
i want the output as
102
32
74
534532
1
3
. i.e. the numbers before the commas or the dots. i want to discard everything else. Any idea how i can get them???
i have the code to read the file and stuff. i just need the code for this bit.
the output is inside the same while loop that i am using to read the file. the loop is...
while(fscanf(MYFILE,"%s", &STOREHERE) == 1)
{
//my code is here
}
i dont want to put my code here because its a very long and complicated one. n i dont want to confuse all of u by telling u d whole thing. please help me in getting just what i have stated above.
Many thanks in advance,
Tim.
1
#5 Dec 7th, 2009
#include <stdio.h>
int main()
{
const char filename[] = "file.txt";
FILE *file = fopen(filename, "r");
if ( file )
{
char line[BUFSIZ], text[10];
while ( fgets(line, sizeof line, file) )
{
if ( sscanf(line, "%9[^, .]", text) == 1 )
{
printf("text = \"%s\"\n", text);
}
}
}
return 0;
}
/* file.txt
102,2131,432 //format 1
32,531 //format1
74 //format2
534532.5 //format3
1,500 //format1
3,120,352 //format1
*/
/* my output
text = "102"
text = "32"
text = "74"
text = "534532"
text = "1"
text = "3"
*/ Last edited by Dave Sinkula; Dec 7th, 2009 at 11:32 am.
“The essential notion of a socialist society is force.”
— Milton Friedman
— Milton Friedman
•
•
Join Date: Dec 2009
Posts: 3
Reputation:
Solved Threads: 0
0
#6 Dec 8th, 2009
thanks dave... you provide me a very nice information its really very useful for me.
![]() |
Similar Threads
- URGENT: need help with strings and getParameter (Java)
- need urgent help with word to number conversion! (Java)
- URGENT help needed with strings. (C++)
- URGENT: Need help on I/O code! (Java)
- Importing SQL Script File - Urgent !! (Database Design)
- help!! My applet can't run... Urgent!! (Java)
- comparing two strings with linear search.. (Java)
- JSP and Oracle (JSP)
Other Threads in the C Forum
- Previous Thread: print the fields of a structure
- Next Thread: trie
Views: 419 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C
* api array arrays binary binarysearch bind c++ calculator changingto char character code coke command conversion convert data database decimal directory dude dynamic error exec factorial fgetc fgets file fork framework frequency function functions givemetehcodez grade graphics gtkgcurlcompiling homework i/o incrementoperators input insert int integer lazy line linked linked-list linkedlist linux list lists loop lowest malloc matrix measuring memory mysql no-code no-effort no-good open operator output path pointer pointers problem process program programming question read recursion recursive recursiveloop recv reverse scanf send socketprograming source spoonfeeding stack string strings strtok structures student system telephone turbo-c undefined unix user variable whileloop windows






