Is there a way to create a string of characters from a set of elements taken from a existing array?
Example: say I have an array of four characters
#include <cs50.h>
#include <stdio.h>
#include <string.h>
int main (void)
{
char abcd[] = "abcd";
string sabcd = "0";
}
Is there a way I can create strings with a subset of array elements, such as "ac", "cd" and so on?
Edited: added libraries for clarification.
abcdis an array of five characters, since it will include the string terminator.char ac[3] = { abcd[0], abcd[2], '\0' };? You can of course set up the new arrayacusing a loop and some suitable condition for which characters to include. Perhaps if you try something and have problem with your attempt, then you can come back with a new question including a Minimal, Complete, and Verifiable Example and ask for help with whatever problem you have then. Also take some time to read about how to ask good questions.