Basic file handing

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2008
Posts: 15
Reputation: thanatosys is an unknown quantity at this point 
Solved Threads: 1
thanatosys thanatosys is offline Offline
Newbie Poster

Basic file handing

 
0
  #1
Oct 27th, 2008
I am still working on the lovely trie project, now I am working on file input that will be passed into the trie. I receive the following errors when I compile this code.
  1. $ make
  2. gcc -Wall -g -c -o spellback.o spellback.c
  3. spellback.c: In function ‘main’:
  4. spellback.c:36: warning: implicit declaration of function ‘open’
  5. spellback.c:36: warning: assignment makes pointer from integer without a cast
  6. spellback.c:16: warning: unused variable ‘line’
  7. gcc -Wall -g -o simplespell node.o spellback.o

I would like to be able to remove these warnings but the more pressing issue is this bus error:
  1. $ ./simplespell -w filer.c
  2. Opening default file
  3. Closed default file
  4. Opening selected file
  5. Bus error

And of course here is the source code for this:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <stdbool.h>
  6. #include "node.h"
  7.  
  8. #define MAXSIZE 2048
  9.  
  10. int main(int argc, char *argv[]){
  11. int ck;
  12. ck = argc;
  13. //printf("%d\n", ck);
  14.  
  15. FILE *fp;
  16. char line [MAXSIZE];
  17.  
  18. if(ck == 1){
  19. printf("Opening default file\n");
  20. fp = fopen(".WORDS", "r");
  21. fclose(fp);
  22. printf("Closed default file\n");
  23.  
  24. }
  25.  
  26. if(ck == 2){
  27. printf("Invalid Input\n");
  28. }
  29.  
  30. if(ck == 3){
  31. printf("Opening default file\n");
  32. fp = fopen(".WORDS", "r");
  33. fclose(fp);
  34. //point fp to next file
  35. printf("Closed default file\n");
  36. fp = open(argv[2], "r");
  37. printf("Opening selected file\n");
  38. fclose(fp);
  39. printf("Closed selected file\n");
  40. }
  41.  
  42. return 0;
  43. }

Any idea what is causing this bus error? Also the c file does exist and I do have read permissions. As does .WORDS .
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 26
Reputation: vl4kn0 is an unknown quantity at this point 
Solved Threads: 4
vl4kn0's Avatar
vl4kn0 vl4kn0 is offline Offline
Light Poster

Re: Basic file handing

 
1
  #2
Oct 27th, 2008
on 36. line you have fp = open(argv[2], "r"); it should be fp = fopen(argv[2], "r");
Else you have declared variable char line[MAXSIZE]; but you don't use it in your code.
Keep in mind that I'm not native english speaker....
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 15
Reputation: thanatosys is an unknown quantity at this point 
Solved Threads: 1
thanatosys thanatosys is offline Offline
Newbie Poster

Re: Basic file handing

 
0
  #3
Oct 27th, 2008
All good, I realized the one about the line, it will get used later so I am ok with that warning for now. Thanks again for pointing out a typeo , I need to be a bit more careful it seems.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 502 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC