| | |
C++ program help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
C++ Syntax (Toggle Plain Text)
void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27] = "abcdefghijklmnopqrstuvwxyz", int alphacount [27] = 0); void displayTable (int alphacount [27] = 0, char alphabet[27] = "abcdefghijklmnopqrstuvwxyz");
C++ Syntax (Toggle Plain Text)
int foo(int ary[4] = 0) { if( ary != NULL) { for(int i = 0; i < 4; i++) { cout << ary[i] << "\n"; } } cout << "All done\n"; return 1; } int main() { foo(); }
Last edited by Ancient Dragon; Nov 30th, 2008 at 7:10 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jun 2008
Posts: 182
Reputation:
Solved Threads: 18
Check your variable typing (i.e. Max_Lines instead of Max_Line in line 66 but I also read countAlpha instead of alphacount elsewhere).
Also, you should pass lines as argument to the function displayTable.
You have an out-of-boundaries access for your lines array - be careful how you play with
EDIT: Imho it's better to post your code with the help of code tags instead of providing it as an attachment for programs of this size - but this is just a suggestion
Also, you should pass lines as argument to the function displayTable.
You have an out-of-boundaries access for your lines array - be careful how you play with
size <= Max_Lines and how you declared lines itself char lines [Max_Lines][Max_Size]; . Notice that lines is also accessed in displayTable function at line 92 if(!isalpha(lines[n][z])) . Ask yourself: what value does n has?EDIT: Imho it's better to post your code with the help of code tags instead of providing it as an attachment for programs of this size - but this is just a suggestion
Last edited by mrboolf; Nov 30th, 2008 at 7:24 pm.
•
•
Join Date: Nov 2008
Posts: 4
Reputation:
Solved Threads: 0
First I would like to say thanks to everyone's help I have cut down my errors tremendously. Second I am really struggling with this class and I am now at the point to where I'm just trying to pass and leave with the little bit of knowledge I've gained. That being said some of the advice given is beyond me, and though I'm sure you covered these error codes already here is what I'm getting specifically.
•
•
•
•
letterCount2.cpp: In function `void conversion(int, char (*)[80], char*, int*)':
letterCount2.cpp:72: error: default argument given for parameter 3 of `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp:32: error: after previous specification in `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp:72: error: default argument given for parameter 4 of `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp:32: error: after previous specification in `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp: In function `void displayTable(char (*)[80], int*, char*)':
letterCount2.cpp:91: error: default argument given for parameter 2 of `void displayTable(char (*)[80], int*, char*)'
letterCount2.cpp:33: error: after previous specification in `void displayTable(char (*)[80], int*, char*)'
letterCount2.cpp:91: error: default argument given for parameter 3 of `void displayTable(char (*)[80], int*, char*)'
letterCount2.cpp:33: error: after previous specification in `void displayTable(char (*)[80], int*, char*)'
•
•
Join Date: Jun 2008
Posts: 182
Reputation:
Solved Threads: 18
You should remove default values for default arguments from your functions definitions.
For example this code
Would result in the following compile errors:
while this code (without " = 2 " default value in function definition)
will compile fine
For example this code
C++ Syntax (Toggle Plain Text)
#include <iostream> int myfunction(int one, int two = 2); int myfunction(int one, int two = 2) { return one + two; } int main(void) { std::cout << myfunction(1) << std::endl; std::cout << myfunction(1, 3) << std::endl; return EXIT_SUCCESS; }
Would result in the following compile errors:
C++ Syntax (Toggle Plain Text)
test.cpp: In function ‘int myfunction(int, int)’: test.cpp:5: error: default argument given for parameter 2 of ‘int myfunction(int, int)’ test.cpp:3: error: after previous specification in ‘int myfunction(int, int)’
while this code (without " = 2 " default value in function definition)
C++ Syntax (Toggle Plain Text)
#include <iostream> int myfunction(int one, int two = 2); int myfunction(int one, int two) { return one + two; } int main(void) { std::cout << myfunction(1) << std::endl; std::cout << myfunction(1, 3) << std::endl; return EXIT_SUCCESS; }
will compile fine
•
•
Join Date: Nov 2008
Posts: 4
Reputation:
Solved Threads: 0
Hey thanks I got it to compile and run, one obstacle done now to the next, lol. For some reason its not counting the letters correctly in the lines of text i type? I believe that would have something to do with the conversion function or maybe not reading in all the lines of text. Any help would be appreciated.
void readLine (char letter[][Max_Size], int Max_Lines, int& size)
{
cout << "How many lines of text are you entering? ";
cin >> size;
cout << "Type in "<< size <<" lines of text, pressing enter after each line. \n";
if (size <= Max_Lines)
{
for (int i = 0; i <= size; i++)
{
cin.getline (letter[i], Max_Size);
//cout << letter[i];
}
}
else
{
cout << "You have entered too many lines of text, the limit is " << Max_Lines << ".";
}
cout << endl;
}void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27], int alphacount [27])
{
for(i=0;i<26;i++)
{
for(n=0;n<size;n++)
{
for(z=0;lines[n][z]!= '\0'; z++)
{
lines[n][z]= tolower(lines[n][z]);
if (lines[n][z]== alphabet[i])
{
alphacount[i]++;
}
}
}
}
}![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: Function not calling a variable
- Next Thread: MFC Context Menu Via KeyBoard
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






