P
Pontus F
Hi I am learning C++ and I'm still trying to get a grip of pointers
and other C/C++ concepts. I would appreciate if somebody could explain
what's wrong with this code:
---begin code block---
#include "stdio.h"
#include "string.h"
void printText(char c[]){
int len = strlen(c);
for (int i = 0; i < len; i++) {
printf(c);
}
}
void main()
{
char b[2];
b[0] = 'a';
b[1] = 'b';
while(1){
printText(b);
}
}
---end code block---
As you can see, what I'm trying to do is to make a function which
accepts a char array and then prints the entire array, char by char.
This should be trivial, right? I feel like I've missed some major
concept here Enlighten me please
BTW this is what the compiler throws at me:
error C2664: 'printf' : cannot convert parameter 1 from 'char' to
'const char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
regards
Pontus F.
and other C/C++ concepts. I would appreciate if somebody could explain
what's wrong with this code:
---begin code block---
#include "stdio.h"
#include "string.h"
void printText(char c[]){
int len = strlen(c);
for (int i = 0; i < len; i++) {
printf(c);
}
}
void main()
{
char b[2];
b[0] = 'a';
b[1] = 'b';
while(1){
printText(b);
}
}
---end code block---
As you can see, what I'm trying to do is to make a function which
accepts a char array and then prints the entire array, char by char.
This should be trivial, right? I feel like I've missed some major
concept here Enlighten me please
BTW this is what the compiler throws at me:
error C2664: 'printf' : cannot convert parameter 1 from 'char' to
'const char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast
regards
Pontus F.