Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void testas(char *a, char *b)
- {
- unsigned int i = 0;
- while(b[i])
- {
- a[i]=b[i];
- i++;
- }
- }
- void testas2(char *a, char *b)
- {
- memcpy(a, b, strlen(b));
- }
- void testas3(char *a, char *b)
- {
- unsigned int ln = strlen(b);
- if(ln < 4) return;
- *a=*b;
- *(a+1)=*(b+1);
- a[2]=b[2];
- memcpy(a+3, b+3, ln-3);
- }
- int main (int argc, char **argv){
- char tstStr[]="Testas";
- printf("%s\n",tstStr);
- {
- char* str;
- str = malloc(strlen(tstStr)+1);
- if(!str)
- {
- printf("error (1) !\n");
- return 1;
- }
- memset(str,0,strlen(tstStr)+1);
- testas(str,tstStr);
- printf("%s\n",str);
- free(str);
- }
- {
- char* str;
- str = malloc(strlen(tstStr)+1);
- if(!str)
- {
- printf("error (2) !\n");
- return 1;
- }
- memset(str,0,strlen(tstStr)+1);
- testas2(str,tstStr);
- printf("%s\n",str);
- free(str);
- }
- {
- char* str;
- str = malloc(strlen(tstStr)+1);
- if(!str)
- {
- printf("error (3) !\n");
- return 1;
- }
- memset(str,0,strlen(tstStr)+1);
- testas3(str,tstStr);
- printf("%s\n",str);
- free(str);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment