Message from Why Tea in MacGuyver - Skills & Academics #tech
Ah. Just when I think I'm fairly good with computers. Lol.
haha to be fair without the manufacturer's code it's hard to know *exactly* what's going on, you just have some broad ideas of how things work and try poking around in them.
Does a hammer work for poking around?
char c = "Str";
c = 'r';
printf("%s\n", c); //Output: Srr
How to get this to work with an array of strings? I have an array of strings (char*) and I need to modify individual characters of each string. I'm getting segfaulted because I had type `char**`. Now I know `char` works for individual strings but how can I extend that to arrays of them? I'm writing this in C btw.
@John O - obviously I know the answer but I think the outcome would be satisfying.
Ball peen or claw?
Hmm that's a tough one.
1st answer here is easier than me writing out pointer thingy data structure: https://stackoverflow.com/questions/1088622/how-do-i-create-an-array-of-strings-in-c
@Why Tea I'm not sure how that addresses what I'm trying to do here.
Then maybe I don't understand the question. "How do I create an array of strings" is your question, and the second answer in that StackOverflow pretty much covers it.
For multiple cases.
No, I know how to create an array of strings. My question is how to modify individual characters of the strings within said array.
The answer to that is in there if you read carefully.
You're talking about this? Wholesale string copy?
Are you wanting to hit the individual characters in the string and substitute? I think I did miss the gist of what the question is. You have variable length strings, in an array structure (pointers to a bunch of strings) but you want to change just individual characters at will?
It is an array of three strings, each of which is three characters long. It starts out with each string being `"000"`. I need to be able to reach in and change the zeroes to ones where necessary.
But you want to reach in and "touch" each one individually, at will.
Add data type size to array pointer to access each char
Assuming your language won't let you index the array like a normal person
That's all indexes are anyway. Array pointer + index * data type size
Well I mean, obviously it won't.
So do like `*array + (sizeof(char) * 2)`?
@Perihelion - CA Nope, "lvalue required as left operand of assignment"
I think you have to use &array to let it know you're treating the array like a bit literal
Ok do this for c++ *(array+2) to get value
Array + 2 for mem address reference
I'm having a weird problem. Anybody wanna help?
Yeah but it works now. Actually you want the code? See if you can break it. I think it's working. Still need to document it but I can tell you what it accepts.
Okay, I'll DM it to you. But first I'm gonna try to change how I find the command line args to be a little less ridiculous.