|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
|
error message....why?
I am writing a function that will remove all non-letters from words that have been read in to an array. It is giving me this error:
ANSI C++ forbids comparison between pointer and integer here is the code: words was defined in the main cpp file as char words[200][20]; void RemoveNonLetters(char words[][20]) { char temp[100]; int x, y; x = 0; y = 0; for(x=0; x < strlen(words[x]); x++) if(words[x] >= 'A' && words[x] <= 'Z' || words[x] >= 'a' && words[x] <= 'z') { temp[y] = words[x]; y++; } temp[y] = 0; strcpy(words[x], temp); } } thanks ps - i am having one of those days where i cant think of anything, so this is probably an easy fix |
|
|
|
|
|
#2 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
Hi GSXdan,
the error message is caused by the statement: words[x] >= 'A' word is a pointer to a pointer to char (or char**) so words[x] is a pointer to char (or char*), while 'A' is a char, and you cannot compare between them. what you need to do is to create 2 loops,something like this: PHP Code:
|
|
|
|
|
|
#3 |
|
Member (10 bit)
|
wow it would help if i were taught the material right!!! i just tried the example my teacher gave me, and guess what, it doesnt work :/ So let me explain what i have to do and we can go from there.
PART 1 I need to write a program that inputs one word at a time, remvoe all punctuation that may appear at the end of the word. Then i have to convert all capital letters to lowercase. After reading in the word, store it in a character array. Continue doing that until EOF. words is declared as char words[200][20] PART 2 output words... sort so words are in alphabetical order output..... delete all duplicates in the array output.... find all palindromes in array output..... output a table indicating the number of one-letter, two-letter, three-letter words, etc that appear in the array. Only catch is that we cant use subscripts, it has to be done with pointers only( word[i] would have to be *(word+i) so it is basically string manipulation. while writing that i noticed it said one word at a time, so i will have to take a little different approach. we have to have a main cpp file, lab2, and words.cpp file for all functions and a words.h file for declarations. Ill post again once if i have some problems, but feel free to give me any advice on easy ways to do any of these functions. thanks |
|
|
|
|
|
#4 |
|
Member (10 bit)
|
what #include file needs to be in to use string functions?
thanks ^dan |
|
|
|
|
|
#5 |
|
Member (10 bit)
|
ok, here is a situation:
In the input function, I am sending the words array and a counter for the number of words. How do I return two different file types? what would the function header be? Code:
char InputWords(char words[][20], int numwords) {
ifstream inf;
int x = 0;
int numletters = 0;
char temp[20];
numwords=0;
inf.open("lib/words.dat");
while(! inf.EOF) {
inf >> temp;
numletters = strlen(temp);
RemoveNonLetters(temp, numletters);
ChangeCase(temp, numletters);
strcpy(words[x], temp);
x++;
numwords++;
}
return;
}
![]() thanks ^dan |
|
|
|
|
|
#6 |
|
Registered User
Join Date: Nov 2001
Posts: 1,965
|
first, the header for string functions is string.h
second, what do you mean by returning two file types? do you mean returning two different values or something? one way to do it is to create a structure with the two return types you want, let's say you want to return an integer and a char, use: PHP Code:
PHP Code:
PHP Code:
![]() HTH |
|
|
|
|
|
#7 |
|
Member (10 bit)
|
thanks for your help.
^dan |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|