0

INPUT int main(void) { long long cardnumber, calc; string credit[0]; string nonnumeric; //long long calc = card number; int countcardcharacters = 0; long long c;

//user input
do
{
    credit[0]= get_string("Card number: ");
}
while (credit < 0);

printf("%lli\n", cardnumber);


/*checksum(long long calc);
{
    
}*/



cardnumber = long long strtoll(const char credit, &nonnumeric, 10);
calc = cardnumber;
//credit[0] = cardnumber;
//printf("%li\n", credit[0]);

//amex
if (strlen(credit[0]) == 15)
{
    while (credit[0][0] == 3 && (credit[0][1] == 4 || credit[0][1] == 7))
    {
        //american express
        printf("lol");
    }
}

OUTPUT clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow credit.c -lcrypt -lcs50 -lm -o credit credit.c:33:18: error: expected expression cardnumber = long int strtoll(const char credit, &nonnumeric, 10); ^ 1 error generated. : recipe for target 'credit' failed

5
  • The "types" in the man page are not literally used in the function, they indicate the type(s) that the function 1) returns, in this case long int and 2) expects as parameters. That is the proximate cause of the compile error. Jul 9 '20 at 14:39
  • i tried changing the long int to long long but it's still not compiling Jul 9 '20 at 16:12
  • The types are not included in the function call. A valid strtoll call would look something like num = strtoll(somestring,NULL,10). Read the man page to find out why NULL can be used for the second argument. Jul 9 '20 at 17:27
  • "credit.c:41:27: error: incompatible pointer types passing 'string [0]' to parameter of type 'const char *' [-Werror,-Wincompatible-pointer-types] cardnumber = strtoll (credit, NULL, 10); ^~~~~~ /usr/include/stdlib.h:200:54: note: passing argument to parameter '__nptr' here extern long long int strtoll (const char *__restrict __nptr," This is what I got when i tried that that's why I used 'const char' and 'long long'. but thanks for your input. Jul 9 '20 at 17:38
  • I've tried changing the strtoll to atoll but it still won't compile Jul 9 '20 at 18:33
0

The reason that this

cardnumber = strtoll (credit, NULL, 10)

gives this error

error: incompatible pointer types passing 'string [0]' to parameter of type 'const char *' 

is because the variable credit has been declared an array of strings with 0 members here

string credit[0];

I am inclined to think that was not the intention. Prompting the user for a string with get_string is much the same as prompting the user for an integer with get_int as would have been done in mario. Here is the example from the source code that accompanies the lecture to use as a guide.

    // get_string and printf with %s 

        #include<cs50.h> 
        #include<stdio.h> 

       intmain(void) 
       { 
            string s = get_string("What's your name?\n"); 
            printf("hello, %s\n", s);
       }
4
  • thank you, I'll try again. I thought credit[0] meant it had 1 member since it starts counting from zero. Jul 9 '20 at 22:43
  • I tried changing it to "string credit[11]" but i got the same error message still. Jul 9 '20 at 22:45
  • credit should not be an array, just a plain ol' string. Added info to the answer. Jul 9 '20 at 23:22
  • oh alright, thanks Jul 10 '20 at 0:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .