0

So after watching week 1 continued lecture, i saw arrays and how you can use them. Since i skipped the more comfortable problem set 1 credit, i am now trying to do it using arrays.

Here is my code so far:

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


int main(void)
{
    //Create a temp empty array which i will add numbers to
    char temp1[256];
    // Get the credit card number
    long long number = get_long_long("Input a credit card number: ");

    // Converting the number to string
    char cc_number[20];
    sprintf(cc_number, "%lli", number);

    // Store the lenght of the number
    int lenght = strlen(cc_number);

    // For loop used for getting every second number
    for (int i = 0; i < lenght; i++)
    {
        // Checking if at the right index
        if(i % 2 != 0)
        {
            /* Here seems to be the problem, i am trying to add the indexed 
               char(cc_number[i]) to temp1 array */

            strcat(temp1, cc_number[i]);
        }
    }
}

Basically the error is:

incompatible integer to pointer conversion passing 'char' to parameter of 
type 'const char *'; take the address with &

I have searched stackexchange for a while now, but i don't get it. Tried different functions for adding char to array but i can't get it to work :(

1

The strcat function will need two pointers, the name of the array is one the other we can obtain with the address operator & as indicated by your error:

strcat(temp1, &cc_number[i]);
1
  • That fixed it, thank you. Was a bit confused by the error message. Of to the next error :) Mar 6 '18 at 10:23

You must log in to answer this question.

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