mikewbma
May 8th, 2012, 01:07 AM
So I am apply for a job and they want to implement a kind of linked list.
I did the testing before i seperated the file in to the header and move the main to a
testing file.
However after I rearranged the content I get the
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 20
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
Here is my code.
seq.c
#include "seq.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void insert (linkedlist* list, int number, char* msg){
element* ele = malloc(sizeof(element));
ele->number = number;
ele->text = msg;
if (list->size == 0){
list->head = ele;
list->size ++;
list->tail = ele;
ele->next = NULL;
ele->prev = NULL;
}else{
element *temp = ((element*)(list->head));
while(1){
if (temp->number <= number){
if (temp == list->tail){
list->tail = ele;
temp->next = ele;
ele->prev = temp;
list->size++;
break;
}else{
if ((((element*)(temp->next))->number) > number){
((element*)(temp->next))->prev = ele;
ele->next = temp->next;
temp->next = ele;
ele->prev = temp;
list->size++;
break;
}
}
}else{
if (temp == list->head){
list->head = ele;
}else{
(((element*)(temp->prev))->next) = ele;
ele -> prev = (element*)(temp->prev);
}
ele->next = temp;
temp->prev = ele;
list->size++;
break;
}
temp = ((element*)(temp->next));
}
}
}
linkedlist* searchbynumber(linkedlist* list,int lowerbound,int upperbound){
linkedlist *newlist = malloc(sizeof(linkedlist));
element *temp = ((element*)(list->head));
do{
if((temp->number >= lowerbound)&&(temp->number <= upperbound)){
insert(newlist,temp->number,temp->text);
}
temp = temp->next;
}while((temp->number <= upperbound)&&(temp != list->tail));
return newlist;
}
void printlinkedlist(linkedlist* list){
element *temp = ((element*)(list->head));
int counter = 0;
printf ("Size of this linked list is %d\n",list->size);
do{
if (list->size == 0){
printf("Empty linked list\n");
break;
}else{
printf("Position %d number: %d message: %s\n",counter,temp->number,temp->text);
counter++;
temp = ((element*)(temp->next));
}
}while(counter < list->size);
}
void deletebynumber(linkedlist* list,int lowerbound,int upperbound){
element *temp = ((element*)(list->head));
do{
if ((temp->number >= lowerbound) && (temp->number <= upperbound)){
((element*)(temp->prev))->next = temp->next;
((element*)(temp->next))->prev = temp->prev;
}
element *ko = temp;
temp = (element*)temp->next;
free(ko);
}while((temp->number <= upperbound)&&(temp != list->tail));
}
int isSubstring (char* subject, char* string){
int count = 0;
int i;
for (i = 0; i < strlen(subject); i++){
if(subject[i] == string[count]){
count++;
} else {
count = 0;
}
if (count == strlen(string))
return 1;
}
return 0;
}
linkedlist* searchbystring(linkedlist* list,char* string){
linkedlist *newlist = malloc(sizeof(linkedlist));
element *temp = ((element*)(list->head));
do{
if (isSubstring(temp->text,string)){
insert(newlist,temp->number,temp->text);
}
temp = temp->next;
}while(temp != list->tail);
return newlist;
}
seq.h
typedef struct {
void *prev;
int number;
char *text;
void *next;
} element;
typedef struct {
element *head;
int size;
element *tail;
} linkedlist;
void insert (linkedlist* list, int number, char* msg);
linkedlist* searchbynumber(linkedlist* list,int lowerbound,int upperbound);
void printlinkedlist(linkedlist* list);
void deletebynumber(linkedlist* list, int lowebound,int upperbound);
int isSubstring(char* subject, char* string);
linkedlist* searchbystring(linkedlist* list,char* string);
testseq.c
#include "seq.h"
int main(int argc,char* argv[]){
linkedlist *newlist = malloc(sizeof(linkedlist));
{
element* ele1 = malloc(sizeof(element));
ele1->prev = NULL;
ele1->number = 1;
ele1->text = "Sober";
element* ele2 = malloc(sizeof(element));
ele2->prev = ele1;
ele2->number = 2;
ele2->text = "Sober Men";
element* ele3 = malloc(sizeof(element));
ele3->prev = ele2;
ele3->number = 3;
ele3->text = "Sober Male";
ele3->next = NULL;
ele1->next = ele2;
ele2->next = ele3;
newlist->head = ele1;
newlist->tail = ele3;
newlist->size = 3;
insert (newlist,-4,"bad");
insert (newlist,-4,"bad");
insert (newlist,-3,"minus3");
insert (newlist,11,"eleven");
insert (newlist,0,"egg");
insert (newlist,13,"eleven");
insert (newlist,120,"Pwned");
insert (newlist,12,"Noob");
}
linkedlist *slist = searchbystring(newlist,"oo");
deletebynumber(newlist,0,10);
printlinkedlist(slist);
free(newlist);
return 0;
}
please help me
I did the testing before i seperated the file in to the header and move the main to a
testing file.
However after I rearranged the content I get the
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 10 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/crt1.o(.debug_info): relocation 20 has invalid symbol index 20
/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
Here is my code.
seq.c
#include "seq.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void insert (linkedlist* list, int number, char* msg){
element* ele = malloc(sizeof(element));
ele->number = number;
ele->text = msg;
if (list->size == 0){
list->head = ele;
list->size ++;
list->tail = ele;
ele->next = NULL;
ele->prev = NULL;
}else{
element *temp = ((element*)(list->head));
while(1){
if (temp->number <= number){
if (temp == list->tail){
list->tail = ele;
temp->next = ele;
ele->prev = temp;
list->size++;
break;
}else{
if ((((element*)(temp->next))->number) > number){
((element*)(temp->next))->prev = ele;
ele->next = temp->next;
temp->next = ele;
ele->prev = temp;
list->size++;
break;
}
}
}else{
if (temp == list->head){
list->head = ele;
}else{
(((element*)(temp->prev))->next) = ele;
ele -> prev = (element*)(temp->prev);
}
ele->next = temp;
temp->prev = ele;
list->size++;
break;
}
temp = ((element*)(temp->next));
}
}
}
linkedlist* searchbynumber(linkedlist* list,int lowerbound,int upperbound){
linkedlist *newlist = malloc(sizeof(linkedlist));
element *temp = ((element*)(list->head));
do{
if((temp->number >= lowerbound)&&(temp->number <= upperbound)){
insert(newlist,temp->number,temp->text);
}
temp = temp->next;
}while((temp->number <= upperbound)&&(temp != list->tail));
return newlist;
}
void printlinkedlist(linkedlist* list){
element *temp = ((element*)(list->head));
int counter = 0;
printf ("Size of this linked list is %d\n",list->size);
do{
if (list->size == 0){
printf("Empty linked list\n");
break;
}else{
printf("Position %d number: %d message: %s\n",counter,temp->number,temp->text);
counter++;
temp = ((element*)(temp->next));
}
}while(counter < list->size);
}
void deletebynumber(linkedlist* list,int lowerbound,int upperbound){
element *temp = ((element*)(list->head));
do{
if ((temp->number >= lowerbound) && (temp->number <= upperbound)){
((element*)(temp->prev))->next = temp->next;
((element*)(temp->next))->prev = temp->prev;
}
element *ko = temp;
temp = (element*)temp->next;
free(ko);
}while((temp->number <= upperbound)&&(temp != list->tail));
}
int isSubstring (char* subject, char* string){
int count = 0;
int i;
for (i = 0; i < strlen(subject); i++){
if(subject[i] == string[count]){
count++;
} else {
count = 0;
}
if (count == strlen(string))
return 1;
}
return 0;
}
linkedlist* searchbystring(linkedlist* list,char* string){
linkedlist *newlist = malloc(sizeof(linkedlist));
element *temp = ((element*)(list->head));
do{
if (isSubstring(temp->text,string)){
insert(newlist,temp->number,temp->text);
}
temp = temp->next;
}while(temp != list->tail);
return newlist;
}
seq.h
typedef struct {
void *prev;
int number;
char *text;
void *next;
} element;
typedef struct {
element *head;
int size;
element *tail;
} linkedlist;
void insert (linkedlist* list, int number, char* msg);
linkedlist* searchbynumber(linkedlist* list,int lowerbound,int upperbound);
void printlinkedlist(linkedlist* list);
void deletebynumber(linkedlist* list, int lowebound,int upperbound);
int isSubstring(char* subject, char* string);
linkedlist* searchbystring(linkedlist* list,char* string);
testseq.c
#include "seq.h"
int main(int argc,char* argv[]){
linkedlist *newlist = malloc(sizeof(linkedlist));
{
element* ele1 = malloc(sizeof(element));
ele1->prev = NULL;
ele1->number = 1;
ele1->text = "Sober";
element* ele2 = malloc(sizeof(element));
ele2->prev = ele1;
ele2->number = 2;
ele2->text = "Sober Men";
element* ele3 = malloc(sizeof(element));
ele3->prev = ele2;
ele3->number = 3;
ele3->text = "Sober Male";
ele3->next = NULL;
ele1->next = ele2;
ele2->next = ele3;
newlist->head = ele1;
newlist->tail = ele3;
newlist->size = 3;
insert (newlist,-4,"bad");
insert (newlist,-4,"bad");
insert (newlist,-3,"minus3");
insert (newlist,11,"eleven");
insert (newlist,0,"egg");
insert (newlist,13,"eleven");
insert (newlist,120,"Pwned");
insert (newlist,12,"Noob");
}
linkedlist *slist = searchbystring(newlist,"oo");
deletebynumber(newlist,0,10);
printlinkedlist(slist);
free(newlist);
return 0;
}
please help me