Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Initialising array of strings in C

So, I’m basically trying to assign my structure with strings as 0, so then I could change some values later, but I’m getting the warning of "strcpy makes pointer from integer without a cast"
and the code is not working how can I fix it?

my structure is this

struct node{
char ID[3];
char Name[40];
char Code[3];
};

and here is my function

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

void initialiseArray(struct node* arr){
int i;
for(i = 0; i < capacity; i++){
    strcpy(arr[i].ID[3], "0");
    strcpy(arr[i].Name[40], "0");
    strcpy(arr[i].Code[3], "0");
    }
}

>Solution :

arr[i].ID[3] in the function definition must be arr[i].ID. Same for the other two fields. arr[i].ID[3] is a [nonexistant] character of a string, not the string.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading