Number of each character repetition in a string

sahasrara 0 Tallied Votes 127 Views Share

Dear all
This code first read a string then shows number of repetition of each character .
I wrote it by Borland 5.02 .

Good Luck !

//Number of each character repetition in a string
//programming by : Erfan Nasoori
//Email : ketn68@yahoo.com
//Date of send : 2009/1/21

#include <iostream.h>
#include <conio.h>

void main()
{
 char *s;
 int n,i,j,flag[1000],c;

 for(i=0;i<1000;++i)
   flag[i]=0;

 s=new char[1000];

 cout<<"Please enter your string:"<<endl;
 cin.ignore(1,'\n');
 cin.getline(s,1000);

    for(i=0;s[i];++i)
    {
 	c=0;
	if(flag[i]==0)
	{
 	   for(j=i+1;s[j];++j)
       	      if(flag[j]==0 && s[i]==s[j])
 	      {
 		 flag[j]=1;
   		 ++c;
 	      }

 	      if(s[i]!=' ')
 	         cout<<s[i]<<" : "<<c+1<<"\n";
 	      else
 		 cout<<"Space: "<<c+1<<"\n";
 	}
    }
 getch();
}
William Hemsworth 1,339 Posting Virtuoso

Terrible snippet.

> <iostream.h> - use <iostream>
> void main - use int main
> s=new char[1000]; - you never freed that memory
> Badly formatted
> Inappropriate variable names used

sahasrara 0 Newbie Poster

hey William
< this code is not a grand program .
< when you use Borland <iostream> doesn't differ with <iostream.h>
< this dosen't need int main .
< would you like int main !?!
< also , its format just for you , what's your opinion ?!
please see user friendly information of student linked list .

have a good time !

Freaky_Chris 299 Master Poster

int main() is not a choice, it's standard! Don't make people start ranting. Also iostream.h shouldn't be used either, there are a whole host of reasons....and Borland is out dated!

Also you really do need to free the memory! If you don't do it then people using the snippet wont unless they know exactly what is going on.

sahasrara 0 Newbie Poster

Hey freaky
you are very moody .
I didn't said bad pointing that you say me ... .

If you are contending man say me that :
How can we code factorial program just and just with main func recursively????

In this time we need to int main func ? isn't it?

can you utilize or call main func in other func ?

William Hemsworth 1,339 Posting Virtuoso

sahasrara, your posts make no sense.

mvmalderen 2,072 Postaholic

100% agreed with William, and Freaky Chris, you code really is terrible !!

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.