For data insertion in a struct should I put " " or ' '?
For data insertion in a struct should I put " " or ' '?
Your question does not make sense. Perhaps you should write a test program to illustrate the options you're considering.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I have two structs and also a self-referential struct which has as members the other two. I have to create a circular linked list with the last struct. Here are the structs.
The chars must be strings with letters. the ints just numbers. Each data must be separated with semicolon(. How do I do that?Code:typedef struct { int year; int month; int day; }date; typedef struct { double latitude; double longitude; }location; typedef struct incList { char area; date reported; int total_missing; int dead_women; int dead_men; int dead_kids; char cause_of_death; char location_description; location coordinates; char URL; struct incList *next; }incident;
First thing I notice is that your structures contain no "strings" just some doubles, integers, and single character types.The chars must be strings with letters.
Second there are no "separators" involved in the structures, perhaps when you output the data held in the structures you need to print a "separator" character after the data.Each data must be separated with semicolon(. How do I do that?
Do you realize that "char URL;" can only hold a single character?
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
The last two replies don't help me at all.
And, your reply shows that you can not be helped by me.
Goodbye, I hope you never find a programming job with your lack of ability and laziness.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
And I am sure of the fact that you know (because I think that you are not stupid) that there aren't only 2 people on the Internet. If you cannot help me with that :
1) That means that there are other people in that forum who can help
2) You have little to none experience with coding and
3) Your patience is non-existent.
I hope this forum and coding is only hobby of yours.
Why not? Explain yourself, your question really doesn't make much sense. If you want more coherent answers you need to provide more coherent questions.The last two replies don't help me at all.
Do you understand the difference between a character and a string? Your structure definitions strongly hint that you have no idea about the differences.
It would be better if you posted a small complete program that illustrates your problems. Also show what you are inputting into said program and what you are outputting from said program.
I know the difference between a char and a string but I forgot to make in the previous part of a code the chars into arrays. Here is the new part.
I have two problems.Code:typedef struct { int year; int month; int day; }date; typedef struct { double latitude; double longitude; }location; typedef struct incList { /*Gia string ""*/ char area[100]; date reported; int total_missing; int dead_women; int dead_men; int dead_kids; char cause_of_death[150]; char location_description[500]; location coordinates; char URL[100]; struct incList *next; }incident;
1)That this is the first part of the code so I don't have much of the code done.(Pretty much none)
2)How do I make the last struct (that uses self-reference) a circular linked list that makes 10 incidences and put them in a .txt file and print them?
Circular linked lists are a bit of a pain, especially if you care about element order.
Linked list - Wikipedia
A simple example.
Notice that the first node is always at the head of the list, and the remainder appear in reverse order.Code:#include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct node { int data; struct node *next; } node_t; node_t *insert(node_t *list, int data) { node_t *new = malloc(sizeof(*new)); if( list == NULL ) { list = new; new->next = new; } else { new->next = list->next; list->next = new; new->data = data; } return list; } void print(node_t *list) { node_t *temp = list; if ( temp != NULL ) { do { printf("Node=%d\n", temp->data); temp = temp->next; } while ( temp != list ); } } int main ( ) { node_t *list = NULL; for( int i = 0 ; i < 5 ; i++ ) { list = insert(list, i); } print(list); } $ gcc bar.c $ ./a.out Node=0 Node=4 Node=3 Node=2 Node=1
If you want to preserve the order, then the insert() function needs to do some kind of 'find the end' operation beforehand.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
You need to show some actual effort, no one here is going to just give you the solution.That this is the first part of the code so I don't have much of the code done.(Pretty much none)
Break the problem down to manageable chunks, don't try to solve the entire program in one go. I'd start by working on the linked list, there are plenty of explanations available online, and probably in your text book as well to at least get you started.How do I make the last struct (that uses self-reference) a circular linked list that makes 10 incidences and put them in a .txt file and print them?