the code is:
slen=strlen(str);
for(count=0;count<=slen;count++)
{
flag=0;
if((int)str[count]!=32)
{
for(count2=count+1;count2<=slen;count2++)
{
if(str[count]==str[count2])
{
flag=1;
break;
}
}
if(flag==0)
{
ar[ar_count]=str[count];
ar_count++;
}
}
}
at line 5 the != operator working fine but when i put if(((int)str[count]>=65 && (int)str[count]<=90) || ((int)str[count]>=97 && (int)str[count]<=122))
it's not working..
if you've some time to spare and want to know more about this program then read the following:
the question is here. the guy is answered the solution there, but since i don't know anything about pointer or file handeling i didn't understand a thing there...:sad:
so here's my program:
#include <stdio.h>
#include <string.h>
int main()
{
int count=0,count2,ar_count=0,tempch,slen,flag,freq[35],freqcount;
char str[35],ar[35];
printf("Enter the string you want to reorganize: ");
fflush(stdout);
fgets(str,34,stdin);
while(str[count]!='\0') //converting uppercases to lowercase
{
tempch=str[count];
if(tempch>=65 && tempch<=90)
{
tempch+=32;
str[count]=tempch;
}
count++;
}
/* putting unique characters in ar[] */
slen=strlen(str);
for(count=0;count<=slen;count++)
{
flag=0;
if(((int)str[count]>=65 && (int)str[count]<=90) || ((int)str[count]>=97 && (int)str[count]<=122))
{
for(count2=count+1;count2<=slen;count2++)
{
if(str[count]==str[count2])
{
flag=1;
break;
}
}
if(flag==0)
{
ar[ar_count]=str[count];
ar_count++;
}
}
}
/* unique array order alphabatically */
while(1)
{
flag=0;
for(count=0;count<=ar_count-3;count++)
{
if((int)ar[count]>(int)ar[count+1])
{
tempch=ar[count];
ar[count]=ar[count+1];
ar[count+1]=tempch;
flag=1; //flag=1 if the atleast one char got swapped
}
}
if(flag==0)break; //all chars are in order already
}
/* frequency of the array elements */
for(count=0;ar[count]!='\0';count++)
{
freqcount=0;
for(count2=0;count2<=slen;count2++)
{
if(ar[count]==str[count2])freqcount++;
}
freq[count]=freqcount;
}
/* printing the output */
for(count=0;count<=ar[count]!='\0';count++)
{
for(count2=1;count2<=freq[count];count2++)
{
printf("%c",ar[count]);
}
}
return 0;
}
Now when i'm trying to get rid of the non-alphabet characters in line 25 it's not working.
Any help will be appreciated. And any criticism about my bad practice or logic will be welcomed (actually i myself think i kinda overkilled the process :sweat:)
Thank you all.