I am getting this error: .c:28: warning: assignment makes integer from pointer without a cast
-any fixes
thank you

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

void addValue();
void changeId(int data, char *name);

int main()
{
 addValue();
 changeId(2, "Bill ");
 getchar();
 return 0;
}
 
struct Node{
 int data;
 char *name;
}node;
 
void addValue()
{
 node.name = " Tim";
 node.data = 23432;
 printf("Employee number: %d\n",node.data);
 printf("Employee name: %s\n",node.name);
};
 
void changeId(int data, char *name)
{
 *node.name = *name;
 node.data = data;
 printf("Employee number: %d\n",node.data);
 printf("Employee name: %s\n",*name);
};
printf("Employee name: %s\n",[B]*[/B]name);

And functions don't have semicolons at the end.

node.name = " Tim";

Eventually this will cause you issues. C-style strings are copied using strcpy (but they need writeable memory to do so).

>>*node.name = *name;

name is declared as a pointer to a character array. *name is extracting just the first character of that array. You should change this line to

*node.name = name; // remove the asterisk

>>printf("Employee name: %s\n",*name);
the asterisk does not belong here either

printf("Employee name: %s\n",name);

>>*node.name = *name;

name is declared as a pointer to a character array. *name is extracting just the first character of that array. You should change this line to

*node.name = name; // remove the asterisk

>>printf("Employee name: %s\n",*name);
the asterisk does not belong here either

printf("Employee name: %s\n",name);

its still doesn't work, I underline the problem that the compiler is indicating below

#include <stdio.h>
#include <string.h>
void addValue();
void changeId(int data, char *name);
int main()
{
addValue();
changeId(2, "Bill ");
getchar();
return 0;
}
struct Node{
int data;
char *name;
}node;
void addValue()
{
node.name = "Tim";
node.data = 23432;
printf("Employee number: %d\n",node.data);
printf("Employee name: %s\n",node.name);
}
void changeId(int data, char *name)
{
*node.name = name;
node.data = data;
printf("Employee number: %d\n",node.data);
printf("Employee name: %s\n",node.name);
}

there should be no asterisk in front of node.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.