Hi Guys,
I got stuck im my last thread so I have tried to simplify things to see where im going wrong,
In class we just covered basic C functions, I can pass an 'int' back and forth no problems but im getting stuck passing a "string".
This is not class work just me trying to get my head round learning basic C.
I dont know about pointers as yet this has not been covered and I dont think it will be at the level we are at so im trying to do this without pointers.
I want to take user input in the main() function and pass it to another function, manipulate the string in some way(in this case just add ABC to the string passed) and pass it back to the main() function and print it out with the new string3 added to the end of what the user input.
Any help is appreciated.
regards
c
Im using Borland 4.5 C++ Complier on WinXP, and its giving me the error:
Cannot convert 'char *' to 'char' in function main()
Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include <ctype.h>
/*Functions Prototype */
void check_str(char);
/*The main program*/
void main(void)
{
char string1[40];
char answer[40];
printf("\n\n\t\t Enter string1\n\n");
printf("Please enter a string \n");
gets(string1);
strcpy(answer,check_str(string1));
printf("answer = %s",answer);
}
check_str(char string2)
{
char string2[40];
char string3[40];
string3[4]={'a','b','c','\0'};
strcat(string2,string3);
return char string2[40];
}
it trips on this line of code
Code:
strcpy(answer,check_str(string1));