Look at this:
Code:
typedef struct Node
{
Node *next;
char string[50];
Node *prev;
};
int InsertString(Node *n, char *c, int maxlen)
{
int len = strlen(c);
if(len > maxlen)
return -1;
if(len < 1)
return -2;
strcpy(n->string, c);
return 1;
}
int main()
{
Node *thisNode = (Node *)malloc(sizeof(Node));
if(thisNode == NULL) //couldn't allocate...
return 0;
char string[] = "I am a programmer. But why?";
int valid = InsertString(thisNode, string, 50);// struct allows 50 ch.
if(!valid)
{
switch(valid)
{
case -1: printf("String was too big!");
break;
case -2: printf("String was empty!");
break;
default: printf("Undefined problem with string!");
}
}
return 0;
}
Just a simple example of passing parameters, utilizing return values, and using switch statements...
...also notice that if you "typedef" a struct, you can declare variables of it's type and likewise declare in function parameters as if it were an int, double, etc. , that is, without using the "struct" keyword.
...happy coding.