Search Results

Search found 8 results on 1 pages for 'mrblippy'.

Page 1/1 | 1 

  • Strcpy and malloc issues

    - by mrblippy
    Hi, i am having trouble getting a method relating to a linked list working, i get the errors: assignment makes pointer from integer without a cast and passing argument 1 of âstrcpyâ makes pointer from integer without a cast. i have tried to include all the relevant code, but let me know if you need more info. thanks. struct unit { char code[5]; char *name; node_ptr students; }; typedef struct node *node_ptr; struct node { int student_id; char *studentname; node_ptr next; }; void enrol_student(struct unit u[], int n) { int i, p; int student_id = 0; char code_to_enrol[7]; char buffer[100]; node_ptr studentslist; scanf("%s\n", code_to_enrol); for(i=0; i <= n; i++) { studentslist = u[i].students; if(strcmp(u[i].code ,code_to_enrol)<=0) { scanf("enter student details %d %s\n", &studentID, buffer); p = (char *) malloc (strlen(buffer)+1); strcpy(p, buffer); insert_in_order(student_id, buffer, studentslist); } } } void insert_in_order(int n, char *i, node_ptr list) { node_ptr before = list; node_ptr students = (node_ptr) malloc(sizeof(struct node)); students->ID = n; students->name = *i; while(before->next && (before->next->ID < n)) { before = before->next; } students->next = before->next; before->next = students; }

    Read the article

  • Assigning values to chars in structs - c

    - by mrblippy
    Hi, i have been having trouble getting my head around allowing a user to enter words into structs. the struct i am using is below struct class { char class_num[4]; char *class_name } if anyone could point me how to do this or at least point me in the right direction that wuld be great. thanks

    Read the article

  • Sorting array of structs

    - by mrblippy
    Hi, i am having trouble making a method to sort an array of structs. i am tring to sort them in ascending order based on classcode. any help you could give would be appreciated struct unit { char classcode[4]; char *classname; }; void insertion_sort(struct unit u[], int n) { int j, p; struct unit tmp[1]; for(p = 1; p < n; p++) { tmp[0] = u[p]; for(j = p; j > 0 && (strcmp(tmp[j-1].classcode, tmp[p].classcode) > 0); j--) u[j] = u[j-1]; u[j] = tmp[0]; } }

    Read the article

  • Big o notation runtime

    - by mrblippy
    Hi, i have been given some code to work out big o runtimes on them, could someone tell me if i am on the right track or not?? //program1 int i, count = 0, n = 20000; for(i = 0; i < n * n; i++) { count++; } Is that O(n^2)??? //number2 int i, inner_count = 0, n = 2000000000; for(i = 0; i < n; i++) { inner_count++; } is this one O(n)???? //number3 for(i = 0; i < n; i++) { for(j = 0; j < n; j++) { count++; } } O(n^2)????? //number4 for(i = 0; i < n; i++) { for(j = 0; j < i; j++) { for(k = 0; k < j; k++) { inner_count++; } } } is that O(n^3)????? //number5 int i, j, inner_count = 0, n = 30000; for(i = 0; i < n; i++) { for(j = 0; j < i; j++) { inner_count++; } } is that one O(n^3)? //number6 int i, j, k, l, pseudo_inner_count = 0, n = 25; for(i = 0; i < n; i++) { for(j = 0; j < i*i; j++) { for(k = 0; k < i*j; k++) { pseudo_inner_count++; for(l = 0; l < 10; l++); } } } very confused about this one O(n^3)?? //number7 int i, j, k, pseudo_inner_count = 0, n = 16; for(i = n; i > 1; i /= 2) { for(j = 0; j < n; j++) { pseudo_inner_count++; for(k = 0; k < 50000000; k++); } } o(n)???? (i get more lost as they get harder) //number8 int i, j, pseudo_inner_count = 0, n = 1073741824; for(i = n; i > 1; i /= 2) { pseudo_inner_count++; for(j = 0; j < 50000000; j++); } O(n^2)??? If anyone could clarify these and help me understand them better i would be very grateful -cheers

    Read the article

  • assignment makes pointer from integer without a cast

    - by mrblippy
    hi, i am trying to make a linked list and create some methods. but i am getting the error assignment makes pointer from integer without a cast. #include <stdio.h> #include <stdlib.h> #include "students.h" node_ptr create(void) { node_ptr students = (node_ptr) malloc(sizeof(struct node)); students->ID = 0; students->name = NULL; students->next = NULL; return students; } void insert_in_order(int n, node_ptr list) { node_ptr before = list; node_ptr new_node = (node_ptr) malloc(sizeof(struct node)); new_node->ID = n;//error is here i think while(before->next && (before->next->ID < n)) { before = before->next; } new_node->next = before->next; before->next = new_node; }

    Read the article

  • C string program

    - by mrblippy
    Hi, i have been given a task to do ar school that must read three strings in, store the third string in dynamically allocated memory and print out the last 4 letters of the first word alphabetically. Here is the program i have so far but the strings are all stored in different variables, making them hard to sort. if anyone could give me a hand and help me finish this program i would be very grateful. thanks #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char word1[101]; char word2[101]; char* word3; char buffer[101]; scanf("%s", word1); scanf("%s", word2); scanf("%s", buffer); word3 = (char *) malloc(strlen(buffer)+1); strcpy(word3, buffer); return 0; }

    Read the article

  • Allocating memory in char * struct

    - by mrblippy
    hi, im trying to read in a word from a user, then dynamically allocate memory for the word and store it in a struct array that contains a char *. i keep getting a implicit declaration of function âstrlenâ so i know im going wrong somewhere. struct class { char class_code[7]; char *name; }; char buffer[101]; struct unit units[1000]; scanf("%s", buffer); units[0].name = (char *) malloc(strlen(buffer)+1); strcpy(units[0].name, buffer);

    Read the article

  • Allocating memory for a char pointer that is part of a struct

    - by mrblippy
    hi, im trying to read in a word from a user, then dynamically allocate memory for the word and store it in a struct array that contains a char *. i keep getting a implicit declaration of function âstrlenâ so i know im going wrong somewhere. struct class { char class_code[4]; char *name; }; char buffer[101]; struct unit units[1000]; scanf("%s", buffer); units[0].name = (char *) malloc(strlen(buffer)+1); strcpy(units[0].name, buffer);

    Read the article

1