A
alternativa
Hello,
I'm a beginner in C programming and I have a problem that probably will
seem trivial to most of you, however I can't find a solution...
So, I have to write a data base - program should ask the user about the
data and then do some operations like sorting etc. I decided to use a
linked list. The code looks as follows:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
struct somestruct
{
int field1;
char field2[15];
struct somestruct *nextp;
};
typedef struct somestruct DATA;
DATA enter_data () // function that asks the user for the data
{
DATA temp_somestruct;
printf ("field1: ");
scanf ("%s", &(temp_somestruct.field1));
getchar();
printf ("field2: ");
scanf ("%d", &(temp_somestruct.field2));
getchar();
return temp_somestruct;
}
int main (void)
{
enter_data();
return 0;
}
I want the program to use this data for creating a linked list.. then I
would ask the user for next data and add this to this list..
I guess I should now create a pointer to the structure temp_somestruct
(how?) and assign it to some pointer, let's say frstp (for first
pointer), which at the beginnig should be 'equal' NULL...
best regards,
a.
I'm a beginner in C programming and I have a problem that probably will
seem trivial to most of you, however I can't find a solution...
So, I have to write a data base - program should ask the user about the
data and then do some operations like sorting etc. I decided to use a
linked list. The code looks as follows:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<ctype.h>
struct somestruct
{
int field1;
char field2[15];
struct somestruct *nextp;
};
typedef struct somestruct DATA;
DATA enter_data () // function that asks the user for the data
{
DATA temp_somestruct;
printf ("field1: ");
scanf ("%s", &(temp_somestruct.field1));
getchar();
printf ("field2: ");
scanf ("%d", &(temp_somestruct.field2));
getchar();
return temp_somestruct;
}
int main (void)
{
enter_data();
return 0;
}
I want the program to use this data for creating a linked list.. then I
would ask the user for next data and add this to this list..
I guess I should now create a pointer to the structure temp_somestruct
(how?) and assign it to some pointer, let's say frstp (for first
pointer), which at the beginnig should be 'equal' NULL...
best regards,
a.