Thread: replacing charcters for other characters

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    kent
    Posts
    1

    replacing charcters for other characters

    hey, im a bit stuck with this programming assignment ive been playing around with

    i basically have to take a word ( or serval words) and code them

    with an offset provided by the user so

    a=b is the 1st offset
    a=c is the 2nd offset

    and so on

    ive written this as a test , but it doesnt print the final word

    any help???

    ++++++++++++
    (btw... i know i havent covered all the possiblitties but this is just a test)++++++++++



    ************************************************** *******
    insert
    Code:
    #include<stdio.h>
    #include <string.h>
    
    #define size 3
    
    int  main (void)
    
    {
    		
    	char name[]= "aaa";		// setting name input
    	char new_name[size];	               // setting name output
    		
    	int pointer                                                //counter variable
    	int offset;				// setting variable for offset 
    
    	printf(" please enter in a offset" );
    	scanf("%d", &offset);
    	
    	switch (offset)
    
    	{
    		case 1:						
    //************* giving an offset of 1
    
    	for (pointer=0; pointer<=size ; pointer++)																			pointer = 0;
    
    		{	if (name[pointer] = 'a')
    				new_name[pointer] = 'b';
    
    			else if (name[pointer] ='b')
    				new_name[pointer] = 'c';
    
    			else if (name[pointer] = 'c')
    				new_name[pointer] = 'd';
    
    			else (name[pointer] = 'd');
    				new_name[pointer] = 'e';
    		}			
    			
    		printf(" the coding is %d", new_name);
    
    	break;
    
    
    
    		case 2:	
    	//**********giving an offset of 2
    
    	for (pointer=0; pointer<=size ; pointer++)																								// sum = the equation
    	pointer = 0;
    
    		{	if (name[pointer] = 'a')
    				new_name[pointer] = 'c';
    
    			else if (name[pointer] ='b')
    				new_name[pointer] = 'd';
    
    			else if (name[pointer] = 'c')
    				new_name[pointer] = 'e';
    
    			else (name[pointer] = 'd');
    				new_name[pointer] = 'f';
    		}			
    			
    		printf(" the coding is %d", new_name);
    			 
    	break;
    
    		case 3:						
    //************** giving an offset of 3
    
    	for (pointer=0; pointer<=size ; pointer++)																								// sum = the equation
    	pointer = 0;
    
    		{	if (name[pointer] = 'a')
    				new_name[pointer] = 'd';
    
    			else if (name[pointer] ='b')
    				new_name[pointer] = 'e';
    
    			else if (name[pointer] = 'c')
    				new_name[pointer] = 'f';
    
    			else (name[pointer] = 'd');
    				new_name[pointer] = 'g';
    		}			
    			
    		printf(" the coding is %d", new_name);
    			 
    	break;
    			default:
    			printf(" non valid offset") ;
    	}
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    First, enable some warnings in your compiler, so you can catch more problems before you run.
    Code:
    $ gcc -Wall foo.c
    foo.c: In function ‘main’:
    foo.c:27: warning: suggest parentheses around assignment used as truth value
    foo.c:30: warning: suggest parentheses around assignment used as truth value
    foo.c:33: warning: suggest parentheses around assignment used as truth value
    foo.c:40: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘char *’
    foo.c:52: warning: suggest parentheses around assignment used as truth value
    foo.c:55: warning: suggest parentheses around assignment used as truth value
    foo.c:58: warning: suggest parentheses around assignment used as truth value
    foo.c:65: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘char *’
    foo.c:75: warning: suggest parentheses around assignment used as truth value
    foo.c:78: warning: suggest parentheses around assignment used as truth value
    foo.c:81: warning: suggest parentheses around assignment used as truth value
    foo.c:88: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘char *’
    foo.c:94: warning: control reaches end of non-void function
    In particular, make sure case 1: works before copy/pasting mistakes into case 2 and case 3
    - You're using = where you should be using ==
    - You're using %d to print a string.

    > for (pointer=0; pointer<=size ; pointer++) pointer = 0;

    Does your editor have horizontal scroll bars?
    Because there is a bit of bad news stuck far to the right on this line.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Is this C or C++?
    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. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  2. Replies: 10
    Last Post: 07-10-2008, 03:45 PM
  3. Replacing Characters
    By carrotcake1029 in forum C Programming
    Replies: 3
    Last Post: 04-28-2008, 01:08 PM
  4. Replacing characters
    By Beowolf in forum C++ Programming
    Replies: 8
    Last Post: 11-13-2007, 06:17 PM
  5. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM

Tags for this Thread