Thread: I need a little help with c programing

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    5

    I need a little help with c programing

    Hi i just need a help to delete words consecutive repeated

    like :
    text :
    hi hi how are are you you
    print :
    hi how are you

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,922
    What is your idea, and what have you tried?
    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
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,169
    Start with a simpler program to just print each word.

    Then you can expand to comparing adjacent words.
    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.

  4. #4
    Registered User
    Join Date
    Jan 2018
    Posts
    5
    the idea is that , i've seen a question that want me to make a program with three function , one of them is to delete extra spaces , and the second to capitalize the first character in the first word and the delete the other capital characters ,and the third that want me to to delete consecutive repeated words only the consecutive ones. like : the great great the , print : the great the

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,922
    That's not "your idea", that's the requirements. What I meant is how do you intend to do this? How are you going to read the words?
    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

  6. #6
    Registered User
    Join Date
    Jan 2018
    Posts
    5
    using an array

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,922
    Okay, so what is your current code?
    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

  8. #8
    Registered User
    Join Date
    Jan 2018
    Posts
    5
    i didnt do the main yet , i just did the two functions alone as a main , just this one the third i didn't do.
    Code:
    
    
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
     
    int main() {
           char TextBefore[100], TextAfter[100];
           int j = 0, i;
           printf("Enter a String \n");
           gets(TextBefore);
           /* Skips all spaces before first characters */
           while (TextBefore[j] == ' ') {
                  j++;
           }
     
           for (i = 0; TextBefore[j] != '\0'; j++) {
                 if (TextBefore[j] == ' ' && TextBefore[j - 1] == ' ') {
                        continue;
                 }
                 TextAfter[i] = TextBefore[j];
                 i++;
           }
           TextAfter[i] = '\0';
           printf("String without extra spaces\n%s", TextAfter);
     
           getch();
           return 0;
    }
    
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>



    Code:
    int main()
    {
           char TextAfter[100];
           int i = 0;
           gets(TextAfter);
           if (TextAfter[i] >= 'a' && TextAfter[i] <= 'z')
                 TextAfter[i] -= 32;
     
     
           for (i = 1;i < strlen(TextAfter); i++) {
                 if (TextAfter[i] >= 'A' && TextAfter[i] <= 'Z')
                        TextAfter[i] += 32;
           }
           puts(TextAfter);
           getch();
           return 0;
     
          
    }

  9. #9
    Registered User
    Join Date
    Jan 2018
    Posts
    5
    Code:
    #include <stdio.h>
    #include <conio.h>
    #include <string.h>
    
    
    int main()
    {
        char check[100], TextAfter[100];
        int x, j = 0, i = 0, flag = 1, count = 0, c, z;
        gets(TextAfter);
        if (TextAfter[i] == ' ')
            i++;
    
    
        while (TextAfter[i] != ' ')
        {
            check[j] = TextAfter[i];
            count++;
            j++;
            i++;
    
    
        }
    
    
        j = 0;
        x = i;
    
    
        if (count != 0)
        {
            for (z = 0; z < count; z++)
            {
                if (TextAfter[x] != check[j]);
                flag == 0;
    
    
                x++;
                j++;
            }
    
    
            if (flag = 1)
            {
                c == i + count;
                for (z = 0; z < count; z++)
                {
    
    
                    TextAfter[i] == TextAfter[c];
                }
            }
            j = 0;
    
    
        }
        printf("String without extra spaces\n%s", TextAfter);
    
    
    
    
        getch();
        return 0;
    }

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,616
    You're getting somewhere, definitely. I would just make sure that you compile in such a way that catches mistakes like confusing = for == and vice versa.

    Code:
    C:\Users\jk\Desktop>gcc -Wall -std=c99 -c foobar.c
    foobar.c: In function 'main':
    foobar.c:31:13: warning: statement with no effect [-Wunused-value]
                 flag == 0;
                 ^
    foobar.c:37:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
             if (flag = 1)
             ^
    foobar.c:39:13: warning: statement with no effect [-Wunused-value]
                 c == i + count;
                 ^
    foobar.c:42:19: warning: statement with no effect [-Wunused-value]
                       TextAfter[i] == TextAfter[c];
                       ^
    foobar.c:42:44: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
                       TextAfter[i] == TextAfter[c];
                                                ^
    It looks like you have the meaning of these operators backwards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. new to C programing, need a little help
    By mgrenier25 in forum C Programming
    Replies: 10
    Last Post: 01-22-2014, 07:25 PM
  2. DNA C programing
    By S16 in forum C Programming
    Replies: 2
    Last Post: 04-29-2009, 09:54 AM
  3. new to programing need help!!
    By newguy3121 in forum C++ Programming
    Replies: 18
    Last Post: 09-21-2006, 01:59 PM
  4. programing in DOS?
    By k1ll3r in forum C++ Programming
    Replies: 41
    Last Post: 05-31-2006, 04:17 AM
  5. programing
    By NiVaG in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 10-03-2004, 09:19 AM

Tags for this Thread