Thread: K&R solution?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2008
    Location
    Yokohama
    Posts
    48

    K&R solution?

    I was doing one of the K&R exercises which is to write a loop equivalent for the following short program without using || or &&. Usually my solutions are pretty similar to the solution book answer or some of the solutions I can find on the web but this time it is very different. Am I way off with this solution?
    Code:
    for (i = 0; i < lim -1 && (c = getchar()) != '\n' && c != EOF; ++i)
    		s[i] = c;
    to
    Code:
            i = 0;
    	while (i < lim -1)
    		if (c = getchar() != '\n')
    			if (c != EOF)
    				++i;
            s[i] = c;
    Last edited by deadhippo; 05-08-2008 at 02:31 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'Solution' and 'Project' usage in VC++
    By C+/- in forum C++ Programming
    Replies: 2
    Last Post: 01-13-2007, 09:50 AM
  2. anyone know the solution?
    By heeroyung in forum C Programming
    Replies: 15
    Last Post: 09-30-2005, 06:46 AM
  3. My Unix/Linux SECURITY SOLUTION - pls read
    By bjdea1 in forum Linux Programming
    Replies: 3
    Last Post: 04-11-2004, 09:28 PM
  4. Solution - Workspace --> are they the same
    By actionbasti in forum C++ Programming
    Replies: 2
    Last Post: 09-14-2003, 04:05 PM
  5. Problem and Solution
    By DavidP in forum Tech Board
    Replies: 3
    Last Post: 08-18-2003, 02:23 AM