Created
July 4, 2017 04:38
-
-
Save atpons/2bdd08fe9f18bfa86503294eaf86eb86 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> | |
| int strLen(char *s) { | |
| char *sPointer = s; | |
| while (*sPointer) { | |
| sPointer++; | |
| } | |
| return sPointer - s; | |
| } | |
| int strCpy(int i, char *a, char *b) { | |
| a += i - 1; | |
| for (; *b != '\0'; a++, b++) { | |
| *a = *b; | |
| } | |
| *a = '\0'; | |
| return 0; | |
| } | |
| int strIns(int i, char *buf, char *text) { | |
| int n; | |
| char tmpStr[100]; | |
| buf += i; | |
| printf("%d\n", strLen(buf)); | |
| strCpy(1, buf, tmpStr); | |
| printf("Str = %s\n", tmpStr); | |
| buf -= i; | |
| strCpy(i, buf, text); | |
| strCpy(strLen(buf) + 1, buf, tmpStr); | |
| return 0; | |
| } | |
| int main() { | |
| int i; | |
| char a[255], b[255]; | |
| printf("Copy position > "); | |
| scanf("%d", &i); | |
| printf("a > "); | |
| scanf("%20s", a); | |
| printf("b > "); | |
| scanf("%20s", b); | |
| // strCpy(i, a, b); | |
| strIns(i, a, b); | |
| printf("%s\n", a); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment