Thread: What's wrong with the code?

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    What's wrong with the code?

    Code:
    char *p;
    int fd;
    int count;
    fd = open (filename, O_RDONLY, 0777);
    count = read(fd,p,100);
    printf("%d",count);

  2. #2
    Banned
    Join Date
    Nov 2007
    Posts
    678
    Quote Originally Posted by meili100 View Post
    Code:
    char *p;
    int fd;
    int count;
    fd = open (filename, O_RDONLY, 0777);
    count = read(fd,p,100);
    printf("%d",count);
    Code:
    char* p; // wrong!!!
    char p[100]; // this is right :)

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    and this is C not C++
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    http://cpwiki.sf.net/A_pointer_on_pointers
    Uninitialized pointers are very bad. I suggest you read the article to get some insight on pointers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM