0
votes

I try do declare the char but it's not working. Why the output don't appear? Everytime I finish insert the input the program crash.and it shows (note: expected 'const char *' but argument is of type 'int'|) also (warning: passing argument 2 of 'strcpy' makes pointer from integer without a cast [-Wint-conversion]|).

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**Functions**/
void info();
void mark();
void grade();
void report();

/**Variables**/
char stdID[15][20];
char subj[20][20];
char stdgrade[30][20];
int stdMark[30];
int subjTaken[30];


void mark()
{
    printf("Enter subject taken : ");
    scanf("%d", &subjTaken[i]);

    for(j=0;j<subjTaken[i]; j++)
    {
        printf("\nEnter subject : ");
        scanf("%s", &subj[j]);

        printf("Mark for the subject : ");
        scanf("%d", &stdMark[j]);
        grade();
    }
}
void grade()
{
        if((stdMark[i]=0)&&(stdMark[i]<=39))
            {
               strcpy(stdgrade[i],'G');
            }
            else if(stdMark[i]<45)
            {
                strcpy(stdgrade[i], 'E');
            }
            else if(stdMark[i]<50)
            {
                strcpy(stdgrade[i], 'D');
            }
            else if(stdMark[i]<55)
            {
                strcpy(stdgrade[i], 'C');
            }
            else if(stdMark[i]<60)
            {
                strcpy(stdgrade[i], 'C+');
            }
            else if(stdMark[i]<65)
            {
                strcpy(stdgrade[i], 'B');
            }
            else if(stdMark[i]<70)
            {
                strcpy(stdgrade[i], 'B+');
            }
            else if(stdMark[i]<80)
            {
                strcpy(stdgrade[i], 'A-');
            }
            else if(stdMark[i]<90)
            {
                strcpy(stdgrade[i], 'A');
            }
            else if (stdMark[i]<=100)
            {
                strcpy(stdgrade[i],'A+');
            }

}
1
The variable i is not initialized here scanf("%d", &subjTaken[i]);.Achal
Here strcpy(stdgrade[i],'G'); strcpy() second argument should be of char* type but you have provided 'G' which is of char type. Correct it.Achal
Here if((stdMark[i]=0)&&(stdMark[i]<=39)) what stdMark[i]=0 supposed to do ? Its an assignment, you may want to use == or something else.Achal
@Achal In C 'G' is an int. It is a char in C++.Alexey Frunze
= using " " instead of simple quotes ' ' should helpB. Go

1 Answers

0
votes

Make your second argument in double quotes. 'G' is a character (a number), where "G" is a string (an array of characters). The function strcpy doesn't automatically convert a character to a string.

so strcpy(stdgrade[i],'G'); should actually be strcpy(stdgrade[i],"G");