next line problem

This is a discussion on next line problem within the C Programming forums, part of the General Programming Boards category; I am just working on substitution cipher program. reading from one file and substuted characters by other characters and write ...

  1. #1
    Registered User subodh_dg's Avatar
    Join Date
    Mar 2005
    Location
    Nagpur, India
    Posts
    4

    next line problem

    I am just working on substitution cipher program. reading from one file and substuted characters by other characters and write in new file.
    I dont want to substitute space ' ' and next line.
    How can make sure that when function read next line from first file it automatically goes to next line in 2nd file?
    Here the code :
    Code:
    while((ch=fgetc(fpsource))!=EOF)
    	{
    		if(ch!=' ')
    		{
    			for(i=0;i<strlen(str1);i++)
    			{
    				if(ch==str1[i])
    				{	fputc(str2[i],fptarget);
    					break;
    				}
    			}
    		}
    		else
    			fputc(ch,fptarget);
    	}

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Check for '\n' or use fgets().

    [edit]
    And make sure ch is an int or at least not a char.
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. casting problem with strcmp command line arg
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 04-15-2006, 04:40 PM
  2. parsing command line problem
    By Newworld in forum C Programming
    Replies: 1
    Last Post: 11-27-2004, 11:11 PM
  3. read to end of line problem
    By one1082 in forum C++ Programming
    Replies: 3
    Last Post: 11-07-2003, 04:30 PM
  4. Greenhand want help!
    By leereg in forum C Programming
    Replies: 6
    Last Post: 01-29-2002, 06:04 AM
  5. problem passing an option as command line argument
    By papous in forum C Programming
    Replies: 3
    Last Post: 11-22-2001, 06:12 PM

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