Thanks to everyone who replied. I realize that printf was overkill for what
i was trying to do :). Anyway after reading up on how to use the
cin/cout/printf functions i rewrote the code into this (now correctly
indented, sorry about that in the original post):
#include <iostream>
#include <string>
using namespace std;
void printText(char c[]){
cout << c << "\n";
}
int main() {
char myString[20];
while(1){
cout << "Text to print: ";
cin >> myString;
printText(myString);
}
return 0;
}
Which works alot better :)
Thanks again
Pontus F.
"WW" <wolof@freemail.hu> skrev i meddelandet
news:bmfa4l$dv2$1@phys-news1.kolumbus.fi...[color=blue]
> Pontus F wrote:[color=green]
> > 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:[/color]
>
> It is not indented. :-) Please before you post code to newsgroups change
> TABs to (two) spaces. Newsreaders eat TABs on the beginning of lines. :-(
>[color=green]
> > ---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[i]);
> > }
> > }
> >
> > 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[/color]
>
> You need to learn printf! One tutorial, which (with a fast glance) seems[/color]
to[color=blue]
> be good is
http://cplus.about.com/library/weekly/aa032302a.htm
>
> int printf(const char *format, arg1, arg2, arg3, ......);
>
> You did not give the format string, but the argument you want to print!
>
> I could give you the solution, but I will be a stinker. Please read the
> tutorial (it is a short page) and get back here if you could not figure[/color]
out[color=blue]
> what to do. I think if I just tell you what to type there you won't learn
> anything from it.
>
> --
> WW aka Attila
>
>[/color]