Quote:
> I am a beginner
> A simple question to ask..
> If i want to put this 5 letters from Freq[5] to new a array within one
> element, how to do?
> How to create array "fiveletter"
> Freq[0]=A
> Freq[1]=A
> Freq[2]=A
> Freq[3]=A
> Freq[4]=A
> > fiveletter[0]=AAAAA
> Thanks
> Reala
If I understand well what you want : Freq is a array of letters, and
you want to create an array whose first element is the set of Frequ's
chars all-in-one.
Note : 'letter' does not exist in C, I suppose what you want is char.
Ugly solution :
****************************
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
char Freq[5] = "AAAAA";
char fiveletters[1][5];
strncpy(fiveletters[0], Freq, 5*sizeof(char));
printf("Freq=%s\nfiveletters=%s\n", Freq, fiveletters[0]);
return 0;
Quote:
}
****************************
As you can see, the output is quite ugly.
That is because this solution does not use strings (including the
terminating `\0' character).
Better one :
****************************
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
char Freq[6] = "AAAAA\0";
char fiveletters[1][6];
strcpy(fiveletters[0], Freq);
printf("Freq=%s\nfiveletters=%s\n", Freq, fiveletters[0]);
return 0;
Quote:
}
*****************************
Last one :
*****************************
#include <stdio.h>
#include <string.h>
int main(int argc, char * argv[])
{
char Freq[6];
Freq[0]='A';
Freq[1]='A';
Freq[2]='A';
Freq[3]='A';
Freq[4]='A';
Freq[5]='\0';
printf("Freq=%s\n", Freq);
return 0;
Quote:
}
*********************************
I suggest you to get some C tutorial and read carrefully the chapter
about the strings.
I hope this will help.
Xebax