Skip to content

Instantly share code, notes, and snippets.

@Duality4Y
Last active October 8, 2019 09:35
Show Gist options
  • Select an option

  • Save Duality4Y/65c3e82b8b290a8a0ad8d0be744768b2 to your computer and use it in GitHub Desktop.

Select an option

Save Duality4Y/65c3e82b8b290a8a0ad8d0be744768b2 to your computer and use it in GitHub Desktop.
???
/* ??? */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
// two arguments required one string input and one the number of '?' to be added
if(argc != 3)
{
printf("not enough arguments %s <string> <number '?'>\r\n", argv[0]);
return 1;
}
int numbersymbols = atoi(argv[2]);
char bufferstr[1024];
// carefull strlen returns the number of characters does not include the zero terminator.
memcpy(bufferstr, argv[1], strlen(argv[1]) + 1);
printf("bufferstr: %s\r\n", bufferstr);
int i = 0;
for(i = 0; i < numbersymbols; i++)
{
bufferstr[strlen(argv[1]) + i] = '?';
bufferstr[strlen(argv[1]) + i + 1] = '\0'; // always end with a zero terminator!
}
printf("strlen(\"%s\") = %ld \r\n", argv[1], strlen(argv[1]));
printf("result: %s\r\n", bufferstr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment