473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

debugging help please in C

I have three files list.c list.h driver.c. they dont compile properly (they are to be compiled together). i can't find my assignment specs right now, i'll try to post them soon. but maybe someone can make sense of this w/o my instructions?

Expand|Select|Wrap|Line Numbers
  1.  list.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include "list.h"
  6.  
  7. #define LISTSZ(a) (((a)-1)*sizeof(char*)+sizeof(struct list))
  8.  
  9. struct list{
  10.     int size;
  11.     int maxsz;
  12.     char *string[1];
  13. };
  14.  
  15. struct list* startlist (int numstrings)
  16. {    
  17.     struct list *q;
  18.     q=malloc(LISTSIZE(numstrings));
  19.  
  20.     if (q==NULL)
  21.     {
  22.         perror("malloc error\n");
  23.         exit(-1);
  24.     }
  25. q-> size=0;
  26. q-> maxsz= numstrings;
  27.  
  28. return     q;
  29. }
  30.  
  31.  
  32. struct list* insrtstr(char sizestring[], struct list *p){
  33.     char *srcptr, *destptr;
  34.     struct list *q;
  35.     if(p->size == p->maxsz){
  36.         p-> maxsz+= INCRSZ;
  37.         q=realloc(p, LISTSIZE(p->maxsz));
  38.  
  39.         if(q==NULL)
  40.         {
  41.             perror("realloc error\n");
  42.             exit (-1);
  43.         }
  44.         p=q;
  45.     }
  46.     p->string[p->size++]= (char*)strdup(sizestring);
  47.         return p;
  48. }
  49. /*/void sortlist(struct list *p){
  50. //    sizeone++;
  51. //    sizetwo++; */
  52. //
  53.  
  54.  

Expand|Select|Wrap|Line Numbers
  1.  list.h
  2. #ifndef _LIST_H_
  3. #define _LIST_H_
  4.  
  5. #define INITSZ 7
  6. #define INCRSZ 10
  7.  
  8. struct list;
  9.  
  10.     struct list* startlist(int);
  11.     struct list* insrtstr(char [], struct list*);
  12.  
  13.     void sortlist(struct list *);
  14.     struct list* rmvstr(int, struct list *);
  15.  
  16.     void printlist(struct list *);
  17.     void freelist(struct list *);
  18.  
  19.     int strCompare (const void *, const void *);
  20.  
  21. #endif
  22.  

Expand|Select|Wrap|Line Numbers
  1.  driver.c
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include  "list.h"
  6.  
  7. #define MAX_STRING 1024
  8. #define REMOVE_POSITION 4
  9.  
  10. int main(int argc, char *argv[]){
  11.     FILE *in;
  12.     char *str;
  13.     struct list *anotherList;
  14.  
  15.     str=malloc (MAX_STRING);
  16.     in=fopen(argv[1], "r");
  17.  
  18.     anotherList=startlist(INITSZ);
  19.     while(fgets(str, MAX_STRING, in)!= NULL){
  20.         anotherList=insrtstr(str, anotherList);
  21.     }
  22.  
  23.     sortlist(anotherList);
  24.  
  25.     anotherList=rmvstr(REMOVE_POSITION, anotherList);
  26.     printlist(anotherList);
  27.  
  28.     fclose(in);
  29.     free(str);
  30.  
  31.     freelist(anotherList);
  32.     return EXIT_SUCCESS;
  33. }
  34.  
Oct 12 '06 #1
5 2020
Banfa
9,065 Expert Mod 8TB
they dont compile properly
Then you should have posted the compile errors/warnings. I can see anything from a quick glance at the code.
Oct 12 '06 #2
here are my compiler errors

Expand|Select|Wrap|Line Numbers
  1. main203{jprince}9: gcc driver.c list.c list.h -o driver
  2. driver.c:4:19: list.h: No such file or directory
  3. driver.c: In function `main':
  4. driver.c:17: error: `INITSZ' undeclared (first use in this function)
  5. driver.c:17: error: (Each undeclared identifier is reported only once
  6. driver.c:17: error: for each function it appears in.)
  7. driver.c:17: warning: assignment makes pointer from integer without a cast
  8. driver.c:19: warning: assignment makes pointer from integer without a cast
  9. driver.c:24: warning: assignment makes pointer from integer without a cast
  10. list.c:4:18: list.h: No such file or directory
  11. list.c: In function `insrtstr':
  12. list.c:35: error: `INCRSZ' undeclared (first use in this function)
  13. list.c:35: error: (Each undeclared identifier is reported only once
  14. list.c:35: error: for each function it appears in.)
  15.  
Oct 13 '06 #3
Banfa
9,065 Expert Mod 8TB
main203{jprince}9: gcc driver.c list.c list.h -o driver

driver.c:4:19: list.h: No such file or directory

The compiler can not find list.h, is it saved in the same directory as the .c files? If not you will have to add an include path to the compiler command line.

After this all bets are off, it is trying to compile the file without the proper headers included.

list.c:4:18: list.h: No such file or directory

Same again here.
Oct 13 '06 #4
still working on this. i changed the <list.h> to "list.h" which gave me a bunch new errors. they're all "undefined reference to 'some function'", but all my functions are defined in list.h. (yes, list.h is in the correct director with the other two files) so how do i fix the "undefined reference" problem? i am honestly not getting this.
Here are my new errors:

Expand|Select|Wrap|Line Numbers
  1. main203{jprince}6: gcc driver.c list.c list.h -o driver
  2. /tmp/ccsWJzVQ.o: In function `main':
  3. driver.c (.text+0x91) undefined reference to `sortlist'
  4. driver.c (.text+0xa1) undefined reference to `rmvstr'
  5. driver.c (.text+0xb2) undefined reference to `printlist'
  6. driver.c (.text+0xdc) undefined reference to `freelist'
  7. /tmp/ccnS5eoU.o: In function `startlist':
  8. list.c (.text+0xd) undefined reference to `LISTSIZE'
  9. /tmp/ccnS5eoU.o: In function `insrtstr':
  10. list.c (.text+0x88) undefined reference to `LISTSIZE'
  11. collect2: ld returned 1 exit status
  12.  
Oct 13 '06 #5
Banfa
9,065 Expert Mod 8TB
but all my functions are defined in list.h
No. All your functions are declared in list.h.

sortlist, rmvstr, printlist, freelist are not defined anywhere hence the errors.

I function declaration is where you state what the return type of the function is as well as the number of parameters it takes as well as there types, it is followed by a semi colon and has no code block.

Expand|Select|Wrap|Line Numbers
  1. int Add(int op1, int op2); // Declaration of Add
  2.  
A definition as well as having the return type and number of types of parameters also has the code block for the function giving the code to be executed when the function is called, it has no semi colon.

Expand|Select|Wrap|Line Numbers
  1. int Add(int op1, int op2) // Definition of Add
  2. {
  3.     return op1+op2;
  4. }
  5.  
You have link errors, undefined functions because you have declared the functions and tried to call them but not defined them. This makes a lot of sense if you think about it because where you have called the function you are basically saying run the code for the function printlist (for instance) but you have not associated any code with printlist so the linker can't do it.



Note: LISTSIZE is actually defined LISTSZ
Oct 13 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Serdar Kalaycý | last post by:
Hi everybody, My problem seems a bit clichè but I could not work around. Well I read lots of MSDN papers and discussions, but my problem is a bit different from them. When I tried to run the...
10
by: Shawn | last post by:
JIT Debugging failed with the following error: Access is denied. JIT Debugging was initiated by the following account 'PLISKEN\ASPNET' I get this messag in a dialog window when I try to open an...
2
by: Alex Clark | last post by:
Hi All, My system: WinXP Pro, VS.NET 2003, SQL Server Personal Edition. I'm having problems with my old favourite demon, SQL Debugging from within VS.NET. I have to say I've found this...
5
by: phnimx | last post by:
Hi , We have developed a number of plug-in .NET Library Components that we typically deploy with our various applications by installing them into the GAC. Each of the applications contains an...
5
by: rn5a | last post by:
Can someone please suggest me a text editor especially for DEBUGGING ASP scripts apart from Microsoft Visual Interdev? I tried using Visual Interdev & created a project but Interdev generates...
3
by: Rick | last post by:
We have a web site that was built as an ASP.Net Web Site, I am unable to remote debug, when build ing the web site there is not a dll or PDB file generated. I can debug on my local machine but...
0
jwwicks
by: jwwicks | last post by:
Introduction This tutorial describes how to use Visual Studio to create a new C++ program, compile/run a program, resume work on an existing program and debug a program. It is aimed at the...
2
jwwicks
by: jwwicks | last post by:
C/C++ Programs and Debugging in Linux This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
4
by: =?Utf-8?B?TWlrZSBHYWxl?= | last post by:
VS 2008 initially didn't debug classic ASP. SP1 fixes this in some ways. You can debug if you select the debug option to "Start Without Debugging, then either attach the debugger manually or...
7
by: GaryDean | last post by:
(this was also posted on the MSDN WCF forum but the answers over there are not so good) I have a WCF Library hosted by IIS 6 and it all works fine. However I need to step through the code in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.