C/error to run the program
Expert: Narendra - 6/14/2004
Question"void Reverse(char string[]);
Void JoinReverseString (char string[])
Void InsertReverseString (char string[])
Void EncryptStr(char string[],int pos);
void Total ASCII(char string[])
void main (void)
{
char string[100];
char selection;
printf("Enter string : ");
gets(string);
do
{
printf("\n 1 - Reverse String. \n");
printf(" 2 - Joins Reverse String. \n");
printf(" 3 - Inserts Reverse String. \n");
printf(" 4 - Encrypts String. \n");
printf(" 5 - Find Total ASCII Value. \n");
printf(" 6 - End program.\n\n");
printf("Enter selection :");
scanf("%c",&selection);
while (getchar() !='\n');
switch (selection)
{
case '1' : Reverse(string);
break;
case '2' : JoinReverseString (string[]) ;
break;
case '3' : InsertReverseString(string[]);
break;
case '4' : EncryptStr(string[],pos) ;
break;
case '5' : Total ASCII(string[]);
break;
case '6' : break;
default: puts("Not an option");
}
}while (selection != '6');
}
void Reverse(char string[])
{
int i,j=0,length;
char string2[100];
length = strlen(string);
for (i=0;i<length;i++)
{
string2[j] = string[i];
j++;
}
string2[j] = '\0';
strrev(string2);
printf("\n%s\n",string2);
}
Void JoinReverseString (char string[])
{
int len, x;
char* temp;
char* reversed;
len = 0;
while (string[len] != '\0')
len++;
temp = (char*) malloc(2*len+1);
for (x = 0; x < len ; x++) {
temp[x] = string[x];
}
reversed = ReverseString(string);
for (x = 0; x < len ; x++) {
temp[x+len] = reversed[x];
}
temp[2*len] = '\0';
return temp;
}
Void InsertReverseString (char string[])
{
int len, x;
char* temp;
char* reversed;
len = 0;
while (string[len] != '\0')
len++;
temp = (char*) malloc(2*len+1);
for (x = 0; x < len ; x++) {
temp[x*2] = string[x];
}
reversed = ReverseString(string);
for (x = 0; x < len ; x++) {
temp[x*2+1] = reversed[x];
}
temp[2*len] = '\0';
return temp;
}
Void EncryptStr(char string[],int pos);
{
int pos;
printf ("Enter the pos:");
Scanf ("%d", &pos);
Printf ("\nThe character to display:%s\n\n", Encryptstr(string,pos));
}
*******I have wirte this program to run the following functions:
1)Reverse String
2)Join Reverse String
3)Insert Reverse String
4)Encrypt String
5)Find Total ASCII Value
However, I've the error message Error "Declaration syntax error; Size of 'Total' is unknown or zero;Declaration syntax error and Declaration terminated incorrectly.
Can you help me to verify. *** Thanks
AnswerThere are many errors!
I have tried to correct most of the compilation errors.
But, still there are linker errors.
May be you have got another file where you have declared them (Functions TotalASCII, strrev, ReverseString).
Here is the corrected code:
#include <stdio.h>
void Reverse(char string[]);
char * JoinReverseString (char string[]);
char * InsertReverseString (char string[]);
void EncryptStr(char string[]);
void TotalASCII(char string[]);
int main (void)
{
char string[100];
char selection;
printf("Enter string : ");
gets(string);
do
{
printf("\n 1 - Reverse String. \n");
printf(" 2 - Joins Reverse String. \n");
printf(" 3 - Inserts Reverse String. \n");
printf(" 4 - Encrypts String. \n");
printf(" 5 - Find Total ASCII Value. \n");
printf(" 6 - End program.\n\n");
printf("Enter selection :");
scanf("%c",&selection);
while (getchar() !='\n');
switch (selection)
{
case '1' : Reverse(string);
break;
case '2' : JoinReverseString (string) ;
break;
case '3' : InsertReverseString(string);
break;
case '4' : EncryptStr(string) ;
break;
case '5' : TotalASCII(string);
break;
case '6' : break;
default: puts("Not an option");
}
}while (selection != '6');
}
void Reverse(char string[])
{
int i,j=0,length;
char string2[100];
length = strlen(string);
for (i=0;i<length;i++)
{
string2[j] = string[i];
j++;
}
string2[j] = '\0';
strrev(string2);
printf("\n%s\n",string2);
}
char * JoinReverseString (char string[])
{
int len, x;
char* temp;
char* reversed;
len = 0;
while (string[len] != '\0')
len++;
temp = (char*) malloc(2*len+1);
for (x = 0; x < len ; x++) {
temp[x] = string[x];
}
reversed = (char *)ReverseString(string);
for (x = 0; x < len ; x++) {
temp[x+len] = reversed[x];
}
temp[2*len] = '\0';
return temp;
}
char * InsertReverseString (char string[])
{
int len, x;
char* temp;
char* reversed;
len = 0;
while (string[len] != '\0')
len++;
temp = (char*) malloc(2*len+1);
for (x = 0; x < len ; x++) {
temp[x*2] = string[x];
}
reversed = (char *)ReverseString(string);
for (x = 0; x < len ; x++) {
temp[x*2+1] = reversed[x];
}
temp[2*len] = '\0';
return temp;
}
void EncryptStr(char string[])
{
int pos;
printf ("Enter the pos:");
Scanf ("%d", &pos);
//Printf ("\nThe character to display:%s\n\n", Encryptstr(string,pos));
}
I have not tested the code for the functionalities that you have mentioned. I have just tried to remove the compilation errors. So, now, You can add the missing definitions and link the program and create executable and test it.
Get back if you still face problems...
-ssnkumar