Hi everyone,

I am trying to save ip addresses and mac addresses of a node in a structure.I dont know how to assign values.Please help.

#include <stdio.h>
#include<iostream>
#define nodes 15
using namespace std;

struct nodes_struct {
  char ip[19]; 
  char mac[19];
} ;

int main()
{
	char ip[19],mac[19];
	nodes_struct object[nodes];
	
		
		object[0].ip="192.168.1.2";//error 
		
	return 0;

}

If you must use char arrays instead of strings you need to use strcpy(char* dest, char* source) from stdlib to assign values instead of the = operator you have now. With strings you could do str="abc".

Thanks a lot.

Hi everyone,

I am trying to save ip addresses and mac addresses of a node in a structure.I dont know how to assign values.Please help.

#include <stdio.h>
#include<iostream>
#define nodes 15
using namespace std;

struct nodes_struct {
  char ip[19]; 
  char mac[19];
} ;

int main()
{
	char ip[19],mac[19];
	nodes_struct object[nodes];
	
		
		object[0].ip="192.168.1.2";//error 
		
	return 0;

}
#include <stdio.h>
#include <conio.h>
#include <memory.h>
#include <string.h>



struct nodes_struct 
{
  char ip[19]; 
  char mac[19];
} ;

void main()
{
	char *ptr="192.168.0.1";
	nodes_struct nodes[10];
	printf("%s\n",ptr);

	memset(nodes,0,sizeof(nodes_struct));
	memcpy(nodes[0].ip,ptr,strlen(ptr));
	printf("%s %s",ptr,nodes[0].ip);
	
	
	getchar();
}
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.