Copying string to a list node

Hi guys, quick question, aren't any of the following possible?

1
2
3
4
5
6
7
8
9
struct Node{
	char ACNM[60];
	struct Node *next;
} *start;

void cacheData(char a){
     strcpy(a, newNode->ACNM);
     newNode->ACNM = a;
... }


I tried using strcpy() and I got a type mismatch. I tried assigning a like how I did it in my previous code (which was an int type), but I got a lvalue error. I'm guessing you can't assign the data just like that to a data node?
Last edited on
On line 6, char a is a single character, not a pointer to the first character in an array of characters.

If you're using C++ instead of C, you should use std::string instead - then you can just use the = operator to do that (and it handles many other string things for you, along with dynamic resizing handled for you). The syntax you use on line 3 though suggests you're doing this in C, though.
L B wrote:
On line 6, char a is a single character, not a pointer to the first character in an array of characters.


Sorry, can I get a hint on how to do this in C? I saw some samples like:

 
scanf("%s", &newNode->ACNM);


But unfortunately, I can't go that way. I already have my data ready from a file, and I just need to cache the data into memory like what I have coded up there.

EDIT: I re-read your reply and got my hint (of sorts?)

 
void cacheData(char a[60], char b[20], char c[15], double d);


Is that right?
Last edited on
You will want to use char const *a for a c-style string parameter.
Topic archived. No new replies allowed.