Thread: Simple c program to read in input and display output won't compile in VS-08

  1. #1
    Registered User
    Join Date
    Dec 2009

    Simple c program to read in input and display output won't compile in VS-08

    #include <stdio.h>
    #define MAXLINE 1000
    int getline(char line[], int)
    int main()
    	int c, length;
    	char line[MAXLINE];
    	while((length = getline(line, MAXLINE)) > 0){
    	return 0;
    int getline(char s[],int lim)
    	int i = 0;
    	int c;
    	while((c = getchar()) != EOF && c != '\n' && i < lim-1){
    		s[i] = c;
    	if (c == '\n'){
    		s[i] = c;
    	s[i] = '\0';
    	return i;
    I don't see what's wrong with this. Thanks for the help.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    You're missing a terminating semi-colon for your function prototype. Also, getch is non-standard.

    Please post the errors reported by your compiler too.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Join Date
    Aug 2010
    Ontario Canada
    Also you could replace your self-written getline function with the library's fgets() function... unless part of the exercise is to write your own stuff.

  4. #4
    Registered User
    Join Date
    Dec 2009
    Thanks laser. The missing semi colon was the problem. Btw, I'm only using getch so that the program doesn't automatically terminate once the lines are displayed.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to in a hex value and display
    By MMC in forum C Programming
    Replies: 4
    Last Post: 04-11-2002, 01:38 PM
  2. Can't Compile a Simple Program
    By pmoscatt in forum C++ Programming
    Replies: 18
    Last Post: 02-10-2002, 04:14 AM
  3. File Input-output
    By ucme_me in forum C Programming
    Replies: 6
    Last Post: 12-14-2001, 01:27 PM
  4. Simple Compile Time Problem - HELP!
    By kamikazeecows in forum Windows Programming
    Replies: 2
    Last Post: 12-02-2001, 12:30 PM
  5. Input/Output
    By PaulMelia in forum C Programming
    Replies: 3
    Last Post: 12-02-2001, 07:13 AM
Website Security Test