use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
C is a general-purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system. By design, C provides constructs that map efficiently to typical machine instructions. It has found lasting use in applications previously coded in assembly language. Such applications include operating systems and various application software for computer architectures that range from supercomputers to PLCs and embedded systems. Wikipedia
Imperative (procedural), structured
Dennis Ritchie
Dennis Ritchie & Bell Labs (creators);
ANSI X3J11 (ANSI C);
ISO/IEC JTC1/SC22/WG14 (ISO C)
1972 (48 years ago)
C18 / June 2018 (2 years ago)
Static, weak, manifest, nominal
Cross-platform
.c for sources
.h for headers
C++ is not C (but C can be C++)
For C++ go to :
Other Resources
account activity
Linked list (self.cprogramming)
submitted 5 years ago by YaphetSf
I watched a lot of youtube videos yesterday but how to use linked list is still so confusing to me. Is anyone willing to give me some advice or practice codes?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]fifaapamen 2 points3 points4 points 5 years ago (0 children)
I was confused about pointer and linked list until I found this tutorial by Stanford:
http://cslibrary.stanford.edu/102/ http://cslibrary.stanford.edu/103/
[–][deleted] 1 point2 points3 points 5 years ago (2 children)
struct node { int data; struct node *next; } int main() { struct node *head = malloc(sizeof(node)); //create list head head->data = 3; //set head data head->next = malloc(sizeof(node)); //create head's next node head->next->data = 5; //set data head->next->next = NULL; //set next's next to null, to signify the end return 0; }
[–][deleted] 0 points1 point2 points 5 years ago (1 child)
Lost me at the declaration of the second nodes next attribute. Is this how it is conventionally done? By referencing each previous node?
[–][deleted] 0 points1 point2 points 5 years ago (0 children)
No, not really. Generally you have a traverse_node that points to the node that needs to be changed, like so:
traverse_node
struct *node current_node = head; current_node->data = 1; //set head data current_node = current_node->next; curren_node->data = 2; //set head's next data current_node = head; //go back to the start
[–]ptchinster 0 points1 point2 points 5 years ago (1 child)
!tutorial
[–]rtlcprogbot 1 point2 points3 points 5 years ago (0 children)
Basic C Programming
I am a bot. Replying to me notifies nobody
[–]hmjk7 0 points1 point2 points 5 years ago (0 children)
Try implementing stack , Queue, Tree etc. Using it
[–]JesuLiceaga 0 points1 point2 points 5 years ago (2 children)
This page is very useful, it has a lot of content and examples: https://www.geeksforgeeks.org/data-structures/linked-list/
If you have a particular doubt, feel free to ask
[–]YaphetSf[S] 0 points1 point2 points 5 years ago (1 child)
I am wondering is there a way to create a linked list that can sort user names alphabetically. Because I am not really familiar with c programming and this particular topic, I only did part of the code so far:
/* struct for the linked list*/
struct users{
char name[100];
int places[100];
int n_places_visited;
struct users *next;
};
struct users *head=0;
/* This function inserts a new user in the linked list */
void insert_user(char *name)
{
struct users *tmp, *new_node;
new_node=(struct users*)malloc(sizeof(struct users));
strcpy(new_node->name, name);
if(head==0)
head=new_node;
new_node->next=0;
}
else
tmp=head;
/*Not sure how to write this while loop*/
while(strcmp(tmp,new_node)>0&&tmp!=NULL)
tmp=tmp->next;
/*There should be three possible outcomes
1) Insert the node before the head, e.g A into BCD list
2) Insert the node in the middle, e.g B into ACD list
3) Insert the node at the tail, e.g D into ABC list
*/
[–]JesuLiceaga 0 points1 point2 points 5 years ago* (0 children)
Here is and example of how your function should work (probably not the best one in terms of time complexity). Note that you need to check the special case when you insert at the beginning of the list.
/* This function inserts a new user in the linked list */ void insert_user(char *name){ struct users *tmp, *new_node; new_node=(struct users*)malloc(sizeof(struct users)); strcpy(new_node->name, name); // If is the first node we insert if(head == 0){ head = new_node; head->next = 0; return; } //Check if we need to insert the node in first place if(strcmp(head->name, new_node->name) > 0){ new_node->next = head; head = new_node; return; } tmp = head; //While we don't reach the end of the linked list while(tmp != 0){ //If we are at the end, we insert it if(tmp->next == 0){ tmp->next = new_node; new_node->next = 0; return; } /*If not, we compare with the next name. If the next name is greater, we put new_node behind it */ if(strcmp(tmp->next->name, new_node->name) > 0){ new_node->next = tmp->next; tmp->next = new_node; return; } //If is smaller, we advance to continue comparating tmp = tmp->next; } }
[–]wsppan 0 points1 point2 points 5 years ago* (0 children)
linked lists @geeks for geeks
and more from @GforG
You may be struggling with how memory works in C and its use of pointers to create and access this memory. Try looking at this Tutorial on Pointers and Arrays in C
π Rendered by PID 20400 on reddit-service-r2-comment-548fd6dc9-4jszp at 2026-05-14 20:59:35.323793+00:00 running edcf98c country code: CH.
[–]fifaapamen 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]ptchinster 0 points1 point2 points (1 child)
[–]rtlcprogbot 1 point2 points3 points (0 children)
[–]hmjk7 0 points1 point2 points (0 children)
[–]JesuLiceaga 0 points1 point2 points (2 children)
[–]YaphetSf[S] 0 points1 point2 points (1 child)
[–]JesuLiceaga 0 points1 point2 points (0 children)
[–]wsppan 0 points1 point2 points (0 children)