S
Superman859
Hello everyone. Heads up - c++ syntax is killing me. I do quite well
in creating a Java program with very few syntax errors, but I get them
all over the place in c++. The smallest little things get me, which
brings me to...
I'm trying to create a program that gets a string from standard input
and then manipulates it a little bit. It has to be a char array and
not use string from the library.
Here are my prototypes:
//Header file MidTerm.h
#ifndef MIDTERM_H
#define MIDTERM_H
class MidTerm {
public:
void myappend(char [] , char []);
void mytokenizer(char []);
void myreverse(char [] );
void getString();
private:
char originalString[80];
char reversedString[80];
};
#endif
First off, how do I get access to originalString in main()? I always
get an undeclared identifier error. Is this because I didn't
initialize it? The thing is, I'm supposed to take input from the user
for the file - I don't know how to initilize it if that is the case.
I also wasn't sure how large of an array to make in the declaration.
large enough for most sentences...
Here is my main...
#include <iostream>
using namespace std;
#include "MidTerm.h"
int main() {
MidTerm test1;
test1.getString();
//test1.mytokenizer("I coundnt pass original string");
test1.myreverse(originalString);
return 0;
}
It's very simple so far, yet doesn't work. myreverse works if I
actually type in a string rather than use a variable as the
parameter. It reverses all the letters. However, I need to pass the
char array - not static text.
I'm just having a lot of syntax trouble with this char array as
string. How do I initialize it when the string will be input by
user? How do I pass it as a variable to a function correctly? How do
I know the size to use when declaring the char array? How can I get
it to work in the main()?
Any help would greatly be appreciated. I bombed this midterm because
it all dealt with char array, and I'm so used to using String in Java
- much simpler.
Here is that function...
void MidTerm::myreverse(char os[]) {
int i = 0;
int j = strlen(os) -1;
while (i <= strlen(os)) {
reversedString = os[j];
i++;
j--;
}
i = 0;
while (reversedString != '\0') {
cout << reversedString;
i++;
}
}
in creating a Java program with very few syntax errors, but I get them
all over the place in c++. The smallest little things get me, which
brings me to...
I'm trying to create a program that gets a string from standard input
and then manipulates it a little bit. It has to be a char array and
not use string from the library.
Here are my prototypes:
//Header file MidTerm.h
#ifndef MIDTERM_H
#define MIDTERM_H
class MidTerm {
public:
void myappend(char [] , char []);
void mytokenizer(char []);
void myreverse(char [] );
void getString();
private:
char originalString[80];
char reversedString[80];
};
#endif
First off, how do I get access to originalString in main()? I always
get an undeclared identifier error. Is this because I didn't
initialize it? The thing is, I'm supposed to take input from the user
for the file - I don't know how to initilize it if that is the case.
I also wasn't sure how large of an array to make in the declaration.
size when any given sentence can be typed in? I picked 80, a numberFrom what I understand, you must make a size, but how do you know the
large enough for most sentences...
Here is my main...
#include <iostream>
using namespace std;
#include "MidTerm.h"
int main() {
MidTerm test1;
test1.getString();
//test1.mytokenizer("I coundnt pass original string");
test1.myreverse(originalString);
return 0;
}
It's very simple so far, yet doesn't work. myreverse works if I
actually type in a string rather than use a variable as the
parameter. It reverses all the letters. However, I need to pass the
char array - not static text.
I'm just having a lot of syntax trouble with this char array as
string. How do I initialize it when the string will be input by
user? How do I pass it as a variable to a function correctly? How do
I know the size to use when declaring the char array? How can I get
it to work in the main()?
Any help would greatly be appreciated. I bombed this midterm because
it all dealt with char array, and I'm so used to using String in Java
- much simpler.
Here is that function...
void MidTerm::myreverse(char os[]) {
int i = 0;
int j = strlen(os) -1;
while (i <= strlen(os)) {
reversedString = os[j];
i++;
j--;
}
i = 0;
while (reversedString != '\0') {
cout << reversedString;
i++;
}
}