cant get program to work

closed account (G16CpfjN)
HELP I am using Bloodshed's dev c++ and need help with this program before 7:30 tomorrow!
this is my code and i am trying to make a program that can check if a word is a digit word i.e have the letters ONE in order in the word. my errors are at the bottom please please help.

#include <string.h>
#include <stdio.h>
bool TextContainsADigit (char, char);
int main ()
{
char str[15];
char result;
char * pch ={
"ONE",
"TWO",
"THREE",
"FOUR",
"FIVE",
"SIX",
"SEVEN",
"EIGHT",
"NIGHT"
};
printf ("Please enter a word");
pch=strchr(str,'s');
while (pch!=NULL)
if(TextContainsADigit(str, digit){
printf ("not a digit number" ,pch-str+1); );
}else{
printf ("NO");
}
return 0;
}
bool TextContainsADigit (char* text, char* digit)
{
while (*digit != 0)
{
if (*text != *digit)
{
text++;
}
else
{
digit++;
text++;
}

if (*text == 0)
{
return false;
}
}
return true;
}


C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp In function `int main()':
18 C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp initializer for scalar variable requires one element
22 C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp `digit' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
22 C:\Documents and Settings\will\My Documents\c++\comp attempt1.cpp expected `)' before '{' token



can any1 answer asap
many thanks sherb38607

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <string.h>
#include <stdio.h>
using namespace std;
bool TextContainsADigit (char, char);
int main ()
{
string str; //You probably want to use an unlimited string
string result; //And unless you are using one letter as a result, you'll want a string for that too.
char * pch ={
"ONE",
"TWO",
"THREE",
"FOUR",
"FIVE",
"SIX",
"SEVEN",
"EIGHT",
"NINE"
};//Fixed your misspelling of NINE, and WTF are you trying to do here?
printf ("Please enter a word: ");
cin >> str; //Much easier
while (pch!=NULL) //I can't check anything past this right now, sorry...
if(TextContainsADigit(str, digit){
printf ("not a digit number" ,pch-str+1); );
}else{
printf ("NO");
}
return 0;
}
bool TextContainsADigit (char* text, char* digit) // For this, you're using arrays. You're not using the full thing.
{
while (digit != 0)
{
if (*text != *digit)
{
text++;
}
else
{
digit++;
text++;
}

if (*text == 0)
{
return false;
}
}
return true;
}


You can use string::find() to help you, I can't check much code right now.
closed account (G16CpfjN)
kk will do ty XD
The compiler errors are being really clear.

if(TextContainsADigit(str, digit){
Two errors in this line: digit is used for the first time here; the if has no closing parenthesis.

pch is a pointer to a char, but you're assigning it a pointer to a pointer to a char.

pch=strchr(str,'s');
What is this line even supposed to do?
closed account (G16CpfjN)
I dunno what happened i started off fine but i need to make a program that can tell if a word is a digit word and i dunno if that was any close.
thanks
Make sure you research string::find(), it will make your job 200% easier.
It should return something if it's true, another if it's false. (Look it up, I won't post any code)
closed account (G16CpfjN)
thanks i will ry and i will get ack 2 u on how i did
any more help would be much appriciated.
Last edited on
Topic archived. No new replies allowed.