Hi. I am working on a program that would have nothing on input and it will produce 100 lines and on each of them there will be written a string that is a result of combining without any space the following:
firststring+5+thirdstring
where instead of the 5 there will be a string being numerically equal to the value of the i variable from the cycle. Here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
int i;
// char t[100];
for(i=1;i<101;i++)
{
// t[]="firststring"+i+"thirdstring";
char t=concat("firststring", String.valueOf(i), "thirdstring");
printf("%s\n",t);
}
return 0;
}
I have found that I can convert integer i to a string using String.valueOf(i) and that I can concetenate strings using concat() function. I also have troubles printing the resulted string. What do I do wrong?
Here is what compiler wrote:
prog.c: In function 'main':
prog.c:12:14: warning: implicit declaration of function 'concat' [-Wimplicit-function-declaration]
char t=concat("firststring", String.valueOf(i), "thirdstring");
^
prog.c:12:36: error: 'String' undeclared (first use in this function)
char t=concat("firststring", String.valueOf(i), "thirdstring");
^
prog.c:12:36: note: each undeclared identifier is reported only once for each function it appears in
prog.c:13:14: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
printf("%s\n",t);
^