C Does Not Name A Type

Hey Guys,

-_- I don't know If I'm tired, or too lazy to solve this, but this is giving me a hard time.. any suggestions:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
const int c = 1;
char STOP[c];
c = strlen(STOP);
using namespace std;

int main (void)
{

cout << "Enter  letters to be reversed...\n";
gets (STOP);
// More stuff...

return 0;
}


The error is: 'C' Does Not Name A Type
I need some help on this one. Thanks :)

const int c = 1;
...
c = strlen(STOP);


Can you change the value of a constant variable? I thot once declared as constant it cannot be changed?
Hey, thanks for your help!
(Thanks for the tip)

:)

Here it is:
1
2
3
4
5
6
7
8
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>

char STOP[100];
int c = strlen(STOP);
using namespace std;

Your help is greatly appreciated, thanks so much!

What do you want to achieve?

Since 'STOP' contains just garbage on line 6 and still on line 7, it doesn't make sense
Your initial error is because you were trying to execute code outside any function.

1
2
3
4
int c;            //
c = strlen(STOP); // Wrong.

int c = strlen(STOP); // OK. 
@coder77

I didn't give you all of my code. So actually, I think 'STOP' does make sense. Go see my string reversal program. http://www.cplusplus.com/forum/general/57434/

@bbgst

Thanks for the explanation. Stupid beginners mistake.. ;)
Last edited on
Topic archived. No new replies allowed.