Thread: Noob needs help :)

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    21

    Noob needs help :)

    and so your favourite noob is back and asking for help yet one more time.
    So i gotta write a programm that gets a string from a user and modifys it like:
    First calls a func that does the following:
    turns all 'e' & 'y' into 'i'.
    Also turns all 'u' to 'a'. so far so good, i've done it and works....(y this was easy i know)


    BUT ( cause there is always a but to be afraid of...)
    the 2nd part of it is to call a 2nd func that will delete every double character found, like if a character is appearing two times in a row like:
    If there are 2 l's together like "ll" it will delete one of them.If there are 2 t's like "tt" it will delete one of them,and so on.

    Programms example:

    Give string: (user types---->)hello it is a pitty to hear that
    (programm output------>) hilo it is a piti to hiar that.


    So far i got this code on:
    Code:
    #include <stdio.h>
    #include <string>
    char ustr[250],nstr[250],fstr[250];/* USERstring,NEWstring,FINALstring*/
    int i;
    char simplifychar();
    char simplifychar()
    { 
    	if ((ustr[i]=='i') || (ustr[i]=='e') || (ustr[i]=='y'))
    	{	return 'i';
        }
    	else
    	{
    		if (ustr[i]=='u')
    		{
    			return 'a';
    		}
    	else
    		return ustr[i];
    }
    }
    
    char deletedouble();
    char deletedouble()
    {
    if (nstr[i]!=nstr[i+1])/* checks if the next character is the same as the one curently "scanning"*/
    {
    	return nstr[i];
    }
    }
    int main()
    {printf("Give a string:");
    	gets(ustr);
    	for (i=0;i<250;i++)
    	{
    	nstr[i]=simplifychar();
        }
    	for (i=0;i<250;i++)
    	{
    		fstr[i]=deletedouble();
    	}
    	printf("New string :");
    	puts(fstr);
    }
    but when i run it the deletedouble does not do what i want it to do, and i cant find my error :S

    Thanks for your time
    Cursy

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Here is a hint:
    Code:
    char deletedouble()
    {
        if (nstr[i]!=nstr[i+1])/* checks if the next character is the same as the one curently "scanning"*/
        {
            return nstr[i];
        }
        else
        {
            /* Something needs to go in here.  You will probably need to modify the 'i' variable. */
        }
    }
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    21
    thanks for the tip, alltho i still cant figure out what to do...i tryed to increase i counter so if for example S[2]=S[3] then it would return S[3] and would increase i by 2 to get i=4 and keep counter moving, skiping the S[3], but still i cant make it work :S
    Code:
    else
     {
        return nstr[i+1];
        i=i+2;
     }
    this is what i've tryed among many others :S

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    If you return from the function, any line after the return statement won't be executed. You should increment i before you return.
    bit∙hub [bit-huhb] n. A source and destination for information.

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    21
    Code:
    else
    	{
    		k=i;
    		i++;
    		return nstr[k+1];
    		
    	
    	}
    this one works perfecty. thanks man
    if u ever need help in c++ let me know, and ill help ya ( ye thats a joke ofc....)
    and be sure that ill be back with more quetions as i see you enjoy wasting your time with me !!
    im a good thing to waste time xD

    rly thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick noob question
    By thanatos1 in forum C# Programming
    Replies: 2
    Last Post: 06-17-2009, 08:28 PM
  2. Noob Q: How to read a value of a byte in binary?
    By Hitsuin in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2009, 02:46 PM
  3. my noob program doesnt work
    By Scarvenger in forum C++ Programming
    Replies: 2
    Last Post: 10-19-2005, 11:40 AM
  4. noob needs help!!!!:(
    By tykenfitz in forum C Programming
    Replies: 1
    Last Post: 07-10-2005, 08:49 AM
  5. Just a little request from a noob...
    By Lee134 in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 03-18-2005, 05:45 AM