i dont have idea what string function must be used to find consecutive characters . example is the word commit it will output the letter m . tnx for th help :D

i dont have idea what string function must be used to find consecutive characters . example is the word commit it will output the letter m

Your question is not clear. What do you mean to say consecutive characters? The example you gave does not explain the problem well.

Does it really need to be a String function?

Because you can use a simple for loop , if/else statement and a counter to output the consecutive character

Though if (any) String Function is required at all you can use strcmp on each index(a letter) and the index after that(next letter) to know if it is consecutive though it is inefficient.

Does it really need to be a String function?

Because you can use a simple for loop , if/else statement and a counter to output the consecutive character

Though if (any) String Function is required at all you can use strcmp on each index(a letter) and the index after that(next letter) to know if it is consecutive though it is inefficient.

Note that your going to find a way to get each letter according to its index and use a for loop and if else statement along with strcmp to find a consecutive letter.

input a string and need to identify the letters that occur consecutively

for example the string input is : ABBCCDFEE

it will output the characters that occur consecutively
the output now is : B C E, because these letters occur consecutively

for(i=0;A[i]!=NULL;i++)
{
if(A[i]==A[i])
printf("%c",A[i]);

there's my code . its a bit frustrating
my problem is how am i supposed to compare the first letter to the next one and so on ..

Here's the answer plus it has a string function

#include<stdio.h>
#include<string.h>

main(){
	char string[20];
	int i;
	printf("Enter string:");
	scanf("%s",string);
	
    for(i=0;i<strlen(string);i++)
    {
    if(string[i]==string[i+1]){
    printf("%c\n", string[i]);
    }
    }
}

Why are there so many worthless posts here? The answer is extremely simple:

There is no function (why would there be?)
Use = on 2 consecutive characters.

Here's the answer plus it has a string function

We don't give answers here. We help them fix their attempt.

As for your code: main(){ -- main is always an int scanf("%s",string); -- see this for(i=0;i<strlen(string);i++) -- why calculate the length of the string every time through the loop? That's a waste of resources. And why compare the last character with the \0 at the end? if(string[i]==string[i+1]){ -- indent properly printf("%c\n", string[i]); -- indent properly
where's your required return statement?

Why are there so many worthless posts here? The answer is extremely simple:

There is no function (why would there be?)
Use = on 2 consecutive characters.


We don't give answers here. We help them fix their attempt.

As for your code: main(){ -- main is always an int scanf("%s",string); -- see this for(i=0;i<strlen(string);i++) -- why calculate the length of the string every time through the loop? That's a waste of resources. And why compare the last character with the \0 at the end? if(string[i]==string[i+1]){ -- indent properly printf("%c\n", string[i]); -- indent properly
where's your required return statement?

Sorry about that the problem seems so easy I just couldn't help myself do the code,
and yes I agree the using strlen is a waste of time but I just thought that a (any)string function a part of his requirement so I include it.

Here is the code

#include<stdio.h>
#include<conio.h>
main()
{
      char str[50];
      int i;
      printf(" Enter String\n");
      scanf("%s",str);
      
      for(i=0;str[i]!='\0';i++)
      {
          if(str[i]==str[i+1])
            printf ("%c\n", str[i]);
            }
            getch();
            }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.