I am using C++ to write a program for class, and I keep getting the following error: "error C2064: term does not evaluate to a function taking 2 arguments".
The error is in reference to this function call:
grade (gradeBook, grade);
and here is the prototype and the actual function:
void grade(studentInfo gradeBook [ ], char%26amp;);
void grade (studentInfo gradeBook [ ], char%26amp; grade)
{
int student;
int score;
for (student=0; student%26lt;=10-1;student++)
{
if (70 %26lt; score %26lt; 90)
grade = 'S';
else if ( score %26gt; 90)
grade = 'O';
else (score %26lt; 70);
grade = 'U';
}
}
C++ Error Message?
You have a function named 'grade' but inside your 'for' loop you have assignment statements such as 'grade = 'S';' which use 'grade' as a variable, but never declared a variable named 'grade' or told the compiler what data type the variable 'grade' is.
Also you cannot use the same identifier 'grade' for the name of a function and also as the name of a variable. So use a different name for the variable such as 'myGrade'. But before you assign any value to 'myGrade' you must declare that it is a variable of type char by writing the statement
char myGrade;
A third issue is in your conditional
if(70 %26lt; score %26lt; 90)
That is incorrect syntax. This conditional is proper:
if(70 %26lt; score %26amp;%26amp; score %26lt; 90)
But if you use 'myScore' as the variable name, then that would be
if(70 %26lt; myScore %26amp;%26amp; myScore %26lt; 90)
If you want to include values of 70 and 90, then you might want to use %26lt;= instead of %26lt;.
Reply:Your function signature is different to the function itself.
Change the first
void grade(studentInfo gradeBook [ ], char%26amp;);
to
void grade(studentInfo gradeBook [ ], char%26amp; grade);
Sunday, August 2, 2009
C loop, giving me trouble !! Can anyone help..?
i have this code to test for palindromes, it functions perfectly well on the first test, but as the program continues to check for more after the first word it keeps printing not palindrome, once it wasnt the first word typed, run it pls, and you'll c what im talking about. Can anyone help me fix it..?
#include %26lt;stdio.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;string.h%26gt;
int isPalindrome( char *s);
int main (void)
{
int i=0;
int ch;
char s[100];
while (1){
while ((ch = getchar()) != ('\n')){
if (isalpha(ch)){
ch=toupper(ch);
s[i]=ch;
i++;
}
}
s[i]='\0';
if (isPalindrome(s) ==1){
printf("is palindrome\n");
}
else{
printf("not palindrome\n");
}
system("Pause");
return 0;
}
C loop, giving me trouble !! Can anyone help..?
What you are doing when you pass a char * into a function is essentially passing a pointer to the first char in the array.
This will always start with the first word you enter, and since you are storing all the strings on the same array, there is no way to delineate the different strings.
reseting the i to variable to zero after every call to isPalindrome()
Reply:You need a way to break out of your while(1) loop. Otherwise, you'll just keep asking for chars over and over again.
One way to do this is that if getchar() == \n you can call break;, which will break the outer loop.
A nicer way is to set a flag = true before you enter the main loop, and use while(flag)
then if the character is a carriage return, set flag to false, and the loop rops out naturally.
Reply:You need to initialize your index i in the loop:
while (1){
i = 0;
while ...
You'd be wise to ensure the user doesn't enter more than 100 characters, causing you to overrun your array s[100]. If this is just a toy program for an assignment, it may not matter. Still, it's good to get in the habit of writing robust code.
#include %26lt;stdio.h%26gt;
#include %26lt;ctype.h%26gt;
#include %26lt;string.h%26gt;
int isPalindrome( char *s);
int main (void)
{
int i=0;
int ch;
char s[100];
while (1){
while ((ch = getchar()) != ('\n')){
if (isalpha(ch)){
ch=toupper(ch);
s[i]=ch;
i++;
}
}
s[i]='\0';
if (isPalindrome(s) ==1){
printf("is palindrome\n");
}
else{
printf("not palindrome\n");
}
system("Pause");
return 0;
}
C loop, giving me trouble !! Can anyone help..?
What you are doing when you pass a char * into a function is essentially passing a pointer to the first char in the array.
This will always start with the first word you enter, and since you are storing all the strings on the same array, there is no way to delineate the different strings.
reseting the i to variable to zero after every call to isPalindrome()
Reply:You need a way to break out of your while(1) loop. Otherwise, you'll just keep asking for chars over and over again.
One way to do this is that if getchar() == \n you can call break;, which will break the outer loop.
A nicer way is to set a flag = true before you enter the main loop, and use while(flag)
then if the character is a carriage return, set flag to false, and the loop rops out naturally.
Reply:You need to initialize your index i in the loop:
while (1){
i = 0;
while ...
You'd be wise to ensure the user doesn't enter more than 100 characters, causing you to overrun your array s[100]. If this is just a toy program for an assignment, it may not matter. Still, it's good to get in the habit of writing robust code.
[C#] What's the difference between a null escape character and nullable type?
In C#, what's the difference between a null escape character and nullable type?
// This is an example of a null escape character
char emptyVariable = '\0';
// This is an example of a nullable type
char? emptyVariable = null;
[C#] What's the difference between a null escape character and nullable type?
http://blogs.msdn.com/CSharpFAQ/Default....
http://www.fincher.org/tips/Languages/cs...
spring flowers
// This is an example of a null escape character
char emptyVariable = '\0';
// This is an example of a nullable type
char? emptyVariable = null;
[C#] What's the difference between a null escape character and nullable type?
http://blogs.msdn.com/CSharpFAQ/Default....
http://www.fincher.org/tips/Languages/cs...
spring flowers
Can someone help debug this part of my C Basic program?
//Alphabetization of Multi-Dim string//
void bubblesort(char *R[], int a); //function declaration//
char *restname[20][30]; //Variable in main//
bubblesort(restname[30], 20);//Function bubblesort in main//
void bubblesort(char *R[], int a)//function bubble sort//
{ int i, j; char *hold;
for(i= 0; i %26lt; a; i++)
{ for(j=0; j%26lt;a-1; j++)
{ if(R[j] %26lt; R[j+1])
{ hold = R[j];
R[j] = R[j+1];
R[j+1] = hold;}
}
}
for(i=0; i%26lt;a; i++)
{ printf("%s", R[i]);
printf("\n"); }
} //end function//
This is for my CSE 1320 programming class
I cant figure out how to get the NEW restname multi-dimensional string to print in alphabetical order! I also cannot use any C,Basic built-in sort functions for this project AND i HAVE to use the sort function using pointers
Can somebody PLEASE help me?
If more info is needed, let me know... but i cant post the program in its entirity due to its length exceeding this text box's character limit
Thanks
Can someone help debug this part of my C Basic program?
I get the point. Your program is in descending order. So, you wish to arrange the characters alphabetically in descending order. The program will give you a syntax error because you cannot have a pointer that can also act as an array. Within the arguments of the bubblesort, there is a declared variable "*R[]" of character type. You can have "*R" or "R[]" but not "*R[]".
Bubble sort deals its elements individually, so I think it's better to use "%c" than "%s"
The main part that confuses me much is that you declared a 2-dimensional array to be passed in the arguments of bubblesort but in the bubble sort arguments you placed a 1-dimensional array and its size. If that is what is passed to the arguments then the entire program is logically erroneous because it only applies to a one-dimensional array.
void bubblesort(char *R[], int a); //function declaration//
char *restname[20][30]; //Variable in main//
bubblesort(restname[30], 20);//Function bubblesort in main//
void bubblesort(char *R[], int a)//function bubble sort//
{ int i, j; char *hold;
for(i= 0; i %26lt; a; i++)
{ for(j=0; j%26lt;a-1; j++)
{ if(R[j] %26lt; R[j+1])
{ hold = R[j];
R[j] = R[j+1];
R[j+1] = hold;}
}
}
for(i=0; i%26lt;a; i++)
{ printf("%s", R[i]);
printf("\n"); }
} //end function//
This is for my CSE 1320 programming class
I cant figure out how to get the NEW restname multi-dimensional string to print in alphabetical order! I also cannot use any C,Basic built-in sort functions for this project AND i HAVE to use the sort function using pointers
Can somebody PLEASE help me?
If more info is needed, let me know... but i cant post the program in its entirity due to its length exceeding this text box's character limit
Thanks
Can someone help debug this part of my C Basic program?
I get the point. Your program is in descending order. So, you wish to arrange the characters alphabetically in descending order. The program will give you a syntax error because you cannot have a pointer that can also act as an array. Within the arguments of the bubblesort, there is a declared variable "*R[]" of character type. You can have "*R" or "R[]" but not "*R[]".
Bubble sort deals its elements individually, so I think it's better to use "%c" than "%s"
The main part that confuses me much is that you declared a 2-dimensional array to be passed in the arguments of bubblesort but in the bubble sort arguments you placed a 1-dimensional array and its size. If that is what is passed to the arguments then the entire program is logically erroneous because it only applies to a one-dimensional array.
HELP NEEDED IN C++ URGENTlY....can u remove files from the foll function...its plzzzzzzzzzzzz?
void function (int len0,int x,int y,int xt,int yt,int xf, int yf,
int px[],int py[],long int speed,char a[],char status,
player cur){FILE *fil;player tp;
//
if( (fil=fopen("topscore.doc","r") )==NULL )
{
fil=fopen("topscore.doc","w");
fprintf(fil,"Amit Bhola\n%d",100);
fclose(fil);
}else fclose(fil);
fil=fopen("topscore.doc","r");
fscanf(fil," %[^\n]",%26amp;tp.name);
fscanf(fil,"%d",%26amp;tp.score);
fclose(fil);
//
for(int j=1;j%26lt;len;j++)
{ px[j-1]=px[j]; py[j-1]=py[j]; }
px[len-1]=xt; py[len-1]=yt;
waitfor(speed);
gotoxy(x,y); cout%26lt;%26lt;" ";
textcolor(LIGHTGREEN);
for(int i=0;i%26lt;len;i++)
{ gotoxy(px[i],py[i]); cprintf("%c",a[i]); }
textcolor(LIGHTRED);
gotoxy(xf,yf); cprintf("O");
textcolor(LIGHTCYAN);
gotoxy(1,1);
cur.score=(len-len0)*10;
if(cur.score%26gt;=tp.score) tp=cur;
cprintf("A N A C O N D A Top Score : %15s : %d ",tp.name,tp.score);
printf("\n");
cprintf("Press esc to EXIT Player : %15s : %d ",cur.name,cur.score);
fil=fopen("topscore.doc","w");
fprintf(fil,"%s\n%d",tp.name,tp.score);
fclose(fil);
return;
HELP NEEDED IN C++ URGENTlY....can u remove files from the foll function...its plzzzzzzzzzzzz?
That's lot of work, you may contact a C++ expert at website like http://askexpert.info/
Reply:omg , wht the heck is that ???????
wht is the point of ur question, be more clear and i'll help u as well as i can. i promise i'll do my best to help , but give an understandable question.
lol
int px[],int py[],long int speed,char a[],char status,
player cur){FILE *fil;player tp;
//
if( (fil=fopen("topscore.doc","r") )==NULL )
{
fil=fopen("topscore.doc","w");
fprintf(fil,"Amit Bhola\n%d",100);
fclose(fil);
}else fclose(fil);
fil=fopen("topscore.doc","r");
fscanf(fil," %[^\n]",%26amp;tp.name);
fscanf(fil,"%d",%26amp;tp.score);
fclose(fil);
//
for(int j=1;j%26lt;len;j++)
{ px[j-1]=px[j]; py[j-1]=py[j]; }
px[len-1]=xt; py[len-1]=yt;
waitfor(speed);
gotoxy(x,y); cout%26lt;%26lt;" ";
textcolor(LIGHTGREEN);
for(int i=0;i%26lt;len;i++)
{ gotoxy(px[i],py[i]); cprintf("%c",a[i]); }
textcolor(LIGHTRED);
gotoxy(xf,yf); cprintf("O");
textcolor(LIGHTCYAN);
gotoxy(1,1);
cur.score=(len-len0)*10;
if(cur.score%26gt;=tp.score) tp=cur;
cprintf("A N A C O N D A Top Score : %15s : %d ",tp.name,tp.score);
printf("\n");
cprintf("Press esc to EXIT Player : %15s : %d ",cur.name,cur.score);
fil=fopen("topscore.doc","w");
fprintf(fil,"%s\n%d",tp.name,tp.score);
fclose(fil);
return;
HELP NEEDED IN C++ URGENTlY....can u remove files from the foll function...its plzzzzzzzzzzzz?
That's lot of work, you may contact a C++ expert at website like http://askexpert.info/
Reply:omg , wht the heck is that ???????
wht is the point of ur question, be more clear and i'll help u as well as i can. i promise i'll do my best to help , but give an understandable question.
lol
C++ coding problem?
we're learning functions in my C++ class, he's given us function main, we're to write sub-functions that'll complete the task libraries are just iostream. I need to return a value to be stored in the variable userInput, but i can't think of a way to do that without modifying the function main (which i'm not allowed to do) or adding a global variable(which i'm not allowed to do) I don't need the code, just a hint (sorry yahoo answers removes my spacing before my code)
// function get Input has already been declared
int main (void)
{
int userInput;
char letter grade;
char gradeSign;
cout %26lt;%26lt; "input number between 1 and 100\n (an invalid value terminates the program)\n";
while (getInput (userInput))
{
//unrelavant code that uses the variable userInput
}
}
//function i've written so far
int getInput (int getInputVar)
{
cout %26lt;%26lt; "Numeric grade: ";
cin %26gt;%26gt; getInputVar;
if (cin.fail() || getInputVar %26lt;0 || getInputVar %26gt; 100)
return 0;
else
return getInputVar;
C++ coding problem?
I am not positive what you are trying to do, are you asking how to let the "return getInputVar;" return to userInput? If so, there's a simple way to do it. Remember that you want the return value to return to something (i.e. using a =...). Hopefully that's enough of a hint.
Reply:1) how is the function "getinput()" declared? Is it declared with a return value, or no return value? example: int getinput() return value, getinput() no return value.
2) how is getinputVar declared in the arguments list for getinput() function? is it "int getinputVar" or "int* getinputVar"?
3)userinput is never assigned a value before being passed to the getinput() function (just poor programming practice, unless it is a pointer to userinput).
Reply:Can you access userInput from the getInput function you've wrote? Try adding userInput = getInputVar; just after the else and before the return statement at the end, and see if it lets you compile. The reason the program outputs random numbers for userInput right now is because you've declared the variable but haven't assigned any value to it yet, so the value stored at that spot in memory is just whatever happened to be stored there last time that memory spot was used by some program. This is called a garbage value because it means absolutely nothing to you or your program.
Reply:u can use main function to call that function and return its value in a variable as::
main()
{
var = fun( parameter list );
}
return type fun( parameter list );
{
return( what u want );
}
var and return type of function should be compatible
// function get Input has already been declared
int main (void)
{
int userInput;
char letter grade;
char gradeSign;
cout %26lt;%26lt; "input number between 1 and 100\n (an invalid value terminates the program)\n";
while (getInput (userInput))
{
//unrelavant code that uses the variable userInput
}
}
//function i've written so far
int getInput (int getInputVar)
{
cout %26lt;%26lt; "Numeric grade: ";
cin %26gt;%26gt; getInputVar;
if (cin.fail() || getInputVar %26lt;0 || getInputVar %26gt; 100)
return 0;
else
return getInputVar;
C++ coding problem?
I am not positive what you are trying to do, are you asking how to let the "return getInputVar;" return to userInput? If so, there's a simple way to do it. Remember that you want the return value to return to something (i.e. using a =...). Hopefully that's enough of a hint.
Reply:1) how is the function "getinput()" declared? Is it declared with a return value, or no return value? example: int getinput() return value, getinput() no return value.
2) how is getinputVar declared in the arguments list for getinput() function? is it "int getinputVar" or "int* getinputVar"?
3)userinput is never assigned a value before being passed to the getinput() function (just poor programming practice, unless it is a pointer to userinput).
Reply:Can you access userInput from the getInput function you've wrote? Try adding userInput = getInputVar; just after the else and before the return statement at the end, and see if it lets you compile. The reason the program outputs random numbers for userInput right now is because you've declared the variable but haven't assigned any value to it yet, so the value stored at that spot in memory is just whatever happened to be stored there last time that memory spot was used by some program. This is called a garbage value because it means absolutely nothing to you or your program.
Reply:u can use main function to call that function and return its value in a variable as::
main()
{
var = fun( parameter list );
}
return type fun( parameter list );
{
return( what u want );
}
var and return type of function should be compatible
Visual C++ - Using DLL Code?
How do I utilize a dll in my new Windows Form Application.
I am using Visual C++ 2005 Express Edition.
I have the following code attached to a button:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
char cmdstr[80]="gui_output.txt\0";
MySEAjov::proc1(cmdstr);
}
I am getting the following errors:
c:\documents and settings\seacm.seadeo\my documents\visual studio 2005\projects\mycomp\mycomp\Fo... : error C2653: 'MySEAjov' : is not a class or namespace name
c:\documents and settings\seacm.seadeo\my documents\visual studio 2005\projects\mycomp\mycomp\Fo... : error C3861: 'proc1': identifier not found
I expect this but don't know how to resolve it. I have a DLL called mycode.dll with a namespace called MySEAjov and a procedure named proc1.
How do I clue the Forms Application in to the fact that the namespace and proc are from a DLL.
Any help would be appreciated.
Visual C++ - Using DLL Code?
Add the lib file to your project. VC will understand that you want to link with it.
Include the header file for your DLL. Depending on how you organise your source files you might have to specifiy the whole path for the header, like this -
#include "C:/code/foobar.h"
or a relative path might be easier.
The biggest problem is that you can only export functions from a DLL, not namespaces. You'd need to write a function called MySEAjov_proc1 with _declspec(dllexport) attributes.
Be careful about C++ function name decoration. There is a tool (in the VC98\Bin directory of your developer studio install) called 'dumpbin'. This allows you to look at the exports from a DLL (and many other things too).
Reply:http://answers.yahoo.com/question/index;...
You still haven't told me if you have the header file and lib import file for the dll. Do you?
You can keep repeating your question endlessly, but if you ask us to play psychics you won't get much help.
You still have to follow C++ rules, regardless of what DLL or library form you use. If you don't have the namespaces, datatypes, functions, whatever declared, usually in the header file for the DLL, you can't compile.
trading cards
I am using Visual C++ 2005 Express Edition.
I have the following code attached to a button:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
char cmdstr[80]="gui_output.txt\0";
MySEAjov::proc1(cmdstr);
}
I am getting the following errors:
c:\documents and settings\seacm.seadeo\my documents\visual studio 2005\projects\mycomp\mycomp\Fo... : error C2653: 'MySEAjov' : is not a class or namespace name
c:\documents and settings\seacm.seadeo\my documents\visual studio 2005\projects\mycomp\mycomp\Fo... : error C3861: 'proc1': identifier not found
I expect this but don't know how to resolve it. I have a DLL called mycode.dll with a namespace called MySEAjov and a procedure named proc1.
How do I clue the Forms Application in to the fact that the namespace and proc are from a DLL.
Any help would be appreciated.
Visual C++ - Using DLL Code?
Add the lib file to your project. VC will understand that you want to link with it.
Include the header file for your DLL. Depending on how you organise your source files you might have to specifiy the whole path for the header, like this -
#include "C:/code/foobar.h"
or a relative path might be easier.
The biggest problem is that you can only export functions from a DLL, not namespaces. You'd need to write a function called MySEAjov_proc1 with _declspec(dllexport) attributes.
Be careful about C++ function name decoration. There is a tool (in the VC98\Bin directory of your developer studio install) called 'dumpbin'. This allows you to look at the exports from a DLL (and many other things too).
Reply:http://answers.yahoo.com/question/index;...
You still haven't told me if you have the header file and lib import file for the dll. Do you?
You can keep repeating your question endlessly, but if you ask us to play psychics you won't get much help.
You still have to follow C++ rules, regardless of what DLL or library form you use. If you don't have the namespaces, datatypes, functions, whatever declared, usually in the header file for the DLL, you can't compile.
trading cards
Subscribe to:
Posts (Atom)