What's wrong with the code?

This is a discussion on What's wrong with the code? within the C++ Programming forums, part of the General Programming Boards category; Code: char *p; int fd; int count; fd = open (filename, O_RDONLY, 0777); count = read(fd,p,100); printf("%d",count);...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    and this is C not C++
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    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, 09: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, 05:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 01: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21