So I can't figure out how to assign a value to a char. What I have below won't compile but if someone can suggest a better solution i would appreciate it.
I'm not really sure what output you want in the end (line 23), but your function dastrings is of type char, which means it should return a char (ie one character), but you try to return an entire string.
Your argument strlen(tmp) should be tmp.length().
Here is your code formatted, but all it does it output "placeholder"
#include <iostream>
#include <string.h>
usingnamespace std;
string dastrings (string line, int lp)
{
int i;
char s;
for ( i = 0; i <= lp; i++)
{
s= line[i]; //this adds the characters of tmp to char s, but on each iteration it overwrites the previous value.
}
return ("placeholder"); //function returns this value, regardless of what code your function executes
}
int main ()
{
string tmp = "poptarts";
cout << dastrings(tmp, tmp.length()) << endl;
return 0;
}
Right, I should be more specific, I have some sudo code and am trying to convert from pascal to c++, the return is not needed at this point but will be needed later, so I just made a place holder. what I want to do is be able to pick a specific number out of a given string and return that char, everything you see is the beginning of that but just not usable.
What I am having issue understanding is why it wont compile saying that "unable to convert char to char[1]"