[Solved] Structs in C Error [closed]

You have several problems: Format specifiers start with a % sign. So change scanf(“d”, &element[j].age); to scanf(“%d”, &element[j].age); and scanf(“s”, &element[j].name); to scanf(“%s”, element[j].name); Wondering why I removed the & from the above scanf? It is because array names gets converted to a pointer to its first element. These printf(“%d. Fav number: %d\n”, k, &element[k].age); … Read more

[Solved] Concept of creating Array of structures in C with three properties [closed]

Hi You can Implement a three dimensional array to store the RGB values and then do the operation you want. The dummy code looks some thing like this: #define TOTAL_NO_OF_PIXEL 1080 //For example total 1080 no of pixels are there int RGBcolor[3][TOTAL_NO_OF_PIXEL]; int main() { for(int cnt=0;cnt<TOTAL_NO_OF_PIXEL;cnt++) { RGBcolor[0][cnt] = RED; RGBcolor[1][cnt] = GREEN; RGBcolor[2][cnt] … Read more

[Solved] How to sort structs from least to greatest in C?

fix like this #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFF_SIZE 32 #define STRUCT_SIZE 512 struct info { char name[BUFF_SIZE]; char stAddress[BUFF_SIZE]; char cityAndState[BUFF_SIZE]; char zip[BUFF_SIZE]; }; void selectionSort(struct info *ptrStruct[], int size);//! int main(void){ int count, size;//! char buffer[600]; struct info *ptrStruct[STRUCT_SIZE]; for (count = 0; count < STRUCT_SIZE; count++){ ptrStruct[count] = (struct info*) … Read more

[Solved] free() not working correctly with struct

It is always a good habit to set the pointer to NULL after freeing it. Since the memory you are accessing is still intact you are seeing right values for l->val. Node *l=malloc(sizeof(Node)); l->key=”foo”; l->val=”bar”; free(l); l = NULL; solved free() not working correctly with struct