- #1
kant
- 388
- 0
I have this input file that contain words. I am suppose to scan this text, and save each word into a some data structure( not part of my question). My question is: How do i get the words but ignore the symbols? The text that is given contain symbols like - , : ; ( ) _ - + - ...etc. Here is what i got so far:
while( scanf(fpname, %s, stun) !=EOF) )
{
******
****
***
pname= AllocateName( stun);
*******
*****
***
*
}
/* here is my allocate name fuction*/
char* AllocateName( char *stun)
{
char*name;
char let;
int num;
num= strlen(stun);
--num;
let=stun[num];
if(let=='.' ||let==',' || let==':')
{
stun[num]='\o';
}
if(!(name=(char*)malloc( strlen(stun)+1, sizeof(char))))
{
printf("problem allocating name\n");
exit(2);
}
strcmp(name, stun);
return name;
}
Yes, yes.. It only care for words that ends with a comma, or a period.
So it is a not a perfect solution. There can be words like:
(log)(base4)(12) <-- consider one word
but not this:
I have the utter-most-hatred-this-lab, where "utter", "most", "hatred", "this" , "lab" are consider individual words, without the god damn '-'. In other word, if i save "utter-most-hatred-this-lab" as a string as stun, than it must be borken up into some unknown number of pieces individually allocate in the heap! unless i am to use [^!@#$%^&*()]. What is a alogant way to god damn do this??
while( scanf(fpname, %s, stun) !=EOF) )
{
******
****
***
pname= AllocateName( stun);
*******
*****
***
*
}
/* here is my allocate name fuction*/
char* AllocateName( char *stun)
{
char*name;
char let;
int num;
num= strlen(stun);
--num;
let=stun[num];
if(let=='.' ||let==',' || let==':')
{
stun[num]='\o';
}
if(!(name=(char*)malloc( strlen(stun)+1, sizeof(char))))
{
printf("problem allocating name\n");
exit(2);
}
strcmp(name, stun);
return name;
}
Yes, yes.. It only care for words that ends with a comma, or a period.
So it is a not a perfect solution. There can be words like:
(log)(base4)(12) <-- consider one word
but not this:
I have the utter-most-hatred-this-lab, where "utter", "most", "hatred", "this" , "lab" are consider individual words, without the god damn '-'. In other word, if i save "utter-most-hatred-this-lab" as a string as stun, than it must be borken up into some unknown number of pieces individually allocate in the heap! unless i am to use [^!@#$%^&*()]. What is a alogant way to god damn do this??
Last edited: