passing a char array to struct char
I cant seem to copy a char array to a struct variable..
1 2 3 4 5 6
|
struct name {
char first_name[10];
}
struct name e;
char string[10] = "copy me";
strcpy(e.first_name, string)
|
does anybody have a clue on how to transfer a char array to a struct variable?
1 2
|
char ch[10] ="oldValue";
ch = "newValue"; //wrong
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <cstring> // did you forget it?
using namespace std;
struct name {
char first_name[10];
};
int main() {
char string[10] = "copy me";
name e;
strcpy(e.first_name , string);
cout <<e.first_name;
}
|
Topic archived. No new replies allowed.