Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given a struct, I am trying to get this pointer to read in a value to then be us

ID: 3776343 • Letter: G

Question

Given a struct, I am trying to get this pointer to read in a value to then be used in a function. I can't seem to get the pointer to read the value correctly. I know the other functions are working correctly, I just can't figure out how to read in a value to then be passed in a function

struct SSL1 {

int value;

struct SSL1 *next;

};

int main() {

int temp;

struct SSL1 *head = NULL;

struct SSL1 *new = NULL;

  

//test case 1

temp = 9;

head = insert(head, temp);

printList(head);

sortList(head);

printf("Enter the value you want sorted: ");

//this is the value that I can't get to read in

scanf("%d", &new->value);

insertSorted(&head, new);

return 0;

}

Explanation / Answer

In the above code all are correct but you have doing small mistack, you was create a structure name like this struct SSL1 *new = NULL; but new is a keyword so it throw error. change the structer name struct to (new1) SSL1 *new1 = NULL;

Then it will work properly read the data from user i already try in my ide it working properly.

#include<stdio.h>

struct SSL1 {
int value;
struct SSL1 *next;
};

int main() {
int temp;
struct SSL1 *head = NULL;
struct SSL1 *new1 = NULL;
  
//test case 1
temp = 9;
printf("Enter the value you want sorted: ");
//this is the value that I can't get to read in
   scanf("%d", &(*new1).value);
   printf(" %d", (*new1).value);
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote