Thread: help in this code

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

    help in this code

    Code:
    #include<stdio.h>
    #include<conio.h>
    #define N 50
    void main()
    {
    	char str[N+1]="aabccbbdds";
    	char ch;
    	int i=0;
    	int count[26]={0};
    	clrscr();
    	while((ch=str[i])!='\0')
    	{
    		count[ch-'a']++;
    		i++;
    	}
    	for(i=0;i<26;i++)
    	{
    		if(count[i])
    		{
    			printf("%c  %d \n",i+'a',count[i]);
    		}
    	}
    	getch();
    }

    /* out put*/
    a 2
    b 3
    c 2
    d 2
    s 1

    /* but i want it should only give me repeating character and its frequency and in next line it should show me the those char which are non repeating one*/

    can you help me plzzzzzz

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Did u run your code the output you want is coming from your code miss

  3. #3
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    And one more thing please use int main instead of void main as in C and in C++ always return type of main is int because we have to tell the system the execution status of the program

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    6
    yes i did run the code.. and this was the output

  5. #5
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by nikki86 View Post
    yes i did run the code.. and this was the output
    Hey i think i miss understood your question may this modified version of your code can help you out

    Code:
    #include<stdio.h>
    
    #define N 50
    void main()
    {
      char str[N+1]="aabccbbdds";
      char ch;
      int i=0;
      int count[26]={0};
    
      while((ch=str[i])!='\0')
        {
          count[ch-'a']++;
          i++;
        }
      for(i=0;i<26;i++)
        {
    #if 0
          if(count[i])
            {
              printf("%c  %d \n",i+'a',count[i]);
            }
    #else
              printf("%c  %d \n",i+'a',count[i]);
    #endif
        }
    
    }

  6. #6
    Registered User
    Join Date
    Nov 2009
    Posts
    6

    not working properly

    please help need this not able to figure it out...
    thank you in advance



    what i want is if i enter a string BIOINFORMATICS

    the output should be::
    non repeated characters are:: BNFRMATCS
    repeated charaters are::
    I 3
    O 2
    Last edited by nikki86; 11-13-2009 at 06:17 AM.

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    6

    help urgent

    Quote Originally Posted by nikki86 View Post
    please help need this not able to figure it out...
    thank you in advance



    what i want is if i enter a string BIOINFORMATICS

    the output should be::
    non repeated characters are:: BNFRMATCS
    repeated charaters are::
    I 3
    O 2
    need help with this type of output

  8. #8
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    i think first of all you should create another thread for another question and please first try out yourself

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    6
    Quote Originally Posted by nikki86 View Post
    please help need this not able to figure it out...
    thank you in advance

    what i want is if i enter a string BIOINFORMATICS

    the output should be::
    non repeated characters are:: BNFRMATCS
    repeated charaters are::
    I 3
    O 2
    Code:
    #include<stdio.h>
    
    #define N 50
    void main()
    {
      char str[N+1]="BIOINFORMATICS";
      char ch;
      int i=0;
      int count[26]={0};
    
      while((ch=str[i])!='\0')
        {
          count[ch-'a']++;
          i++;
        }
      for(i=0;i<26;i++)
        {
          if(count[i])
            {
              printf("%c  %d \n",i+'a',count[i]);
            }
    else
            {
              printf("%c  %d \n",i+'a',count[i]);
            {
        }
    
    }

    No this was the same question for this code .....

    I DONT WANT THE OUTPUT THIS CODE IS GIVING......

    INSTEAD I WANT TO GET OUTPUT AS I HAVE GIVEN IN QUOTE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM