aplelois
asked on
name list
hello,
I have a name list in a .txt file that contains around 2k names of pople and places
I would like to save only the ones that start with e and have only 7 letters
in it, how can I do this?
thanks
I have a name list in a .txt file that contains around 2k names of pople and places
I would like to save only the ones that start with e and have only 7 letters
in it, how can I do this?
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Good catch KK!
Paul
Paul
>>Good catch KK!
thx :)
thx :)
or if you don't need a program, use Perl:
perl -p -e "if /^e/ || #$_ == 8"
perl -p -e "if /^e/ || #$_ == 8"
ASKER
Kelvin_King , Im using Dev C++ and im getting some errors with your code
What errors?
>> Kelvin_King , Im using Dev C++ and im getting some errors with your code
Could you post them here. Thanks.
Could you post them here. Thanks.
ASKER
11 e:\docume~1\tutori~1\c\nam ewi~1\a.c parse error before `char'
13 e:\docume~1\tutori~1\c\nam ewi~1\a.c `currentLine' undeclared (first use in this function)
13 e:\docume~1\tutori~1\c\nam ewi~1\a.c (Each undeclared identifier is reported only once
13 e:\docume~1\tutori~1\c\nam ewi~1\a.c for each function it appears in.)
13 e:\docume~1\tutori~1\c\nam
13 e:\docume~1\tutori~1\c\nam
13 e:\docume~1\tutori~1\c\nam
Try moving the declaration of `currentLine' to the beginning of main().
I think you are missing a semi colon after line 10.
Also, see if you can get use of a C Compiler like gcc. Just download cygwin.
Also, see if you can get use of a C Compiler like gcc. Just download cygwin.
ASKER
>>6 e:\docume~1\tutori~1\c\nam ewi~1\a.c declaration for parameter `currentLine' but no such parameter
#include <stdio.h>
#define MAX_LINE_SIZE 50
int main ()
char currentLine[MAX_LINE_SIZE+ 1];
{
FILE * fp, *outFile;
fp = fopen ("my_file.txt", "r");
outFile = fopen("new_file.txt", "w");
while(fgets(currentLine, MAX_LINE_SIZE, fp)!=NULL)
{
if( tolower((int)currentLine[0 ]) == 'e' && strlen(currentLine)== 8 )
fprintf(outFile, "%s", currentLine);
}
fclose (fp);
fclose (outFile);
return 0;
}
#include <stdio.h>
#define MAX_LINE_SIZE 50
int main ()
char currentLine[MAX_LINE_SIZE+
{
FILE * fp, *outFile;
fp = fopen ("my_file.txt", "r");
outFile = fopen("new_file.txt", "w");
while(fgets(currentLine, MAX_LINE_SIZE, fp)!=NULL)
{
if( tolower((int)currentLine[0
fprintf(outFile, "%s", currentLine);
}
fclose (fp);
fclose (outFile);
return 0;
}
I meant INSIDE the beginning of main().
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
=D thanks it works.. so... who gets the points ?
Split up the points.
btw, having the shift the declaration up a few lines is really strange behaviour. You might wanna get a c compiler anyway. Try gcc.
>>btw, having the shift the declaration up a few lines is really strange behaviour ...
Actually, I should have spotted that. Remember that putting declarations just about anywhere is a C++ feature, C declarations MUST be after another declaration or after a '{' or in global scope.
Paul
Actually, I should have spotted that. Remember that putting declarations just about anywhere is a C++ feature, C declarations MUST be after another declaration or after a '{' or in global scope.
Paul
ASKER
#include <stdio.h>
int main ()
{
FILE * fp;
fp = fopen ("my_file.txt", "w");
char currentLine[MAX_LINE_SIZE+
while(fgets(currentLine, MAX_LINE_SIZE,inFile)!=NUL
{
if( tolower((int)currentLine[0
fprintf(outFile, "%s", currentLine);
}
fclose (fp);
return 0;
}