Last active
October 8, 2019 09:35
-
-
Save Duality4Y/65c3e82b8b290a8a0ad8d0be744768b2 to your computer and use it in GitHub Desktop.
???
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* ??? */ | |
| #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