// ptrSimbAndFunc.cpp : main project file. #include "stdafx.h" #include<stdlib.h> #include<stdio.h> #include<conio.h> #include<malloc.h> #include<string.h> #include<tchar.h> using namespace System; #define eof -1 #define maxline 1000 int getline(char s[], int lim) { int i,c; for(i=0; i<lim-1 && (c=getchar())!=eof && c!='\n'; i++) s[i]=c; s[i]='\0'; return i++; } void strcpy1(char s[], char t[]) { int i=0; while((t[i]=s[i])!='\0') i++; } void strcpy2(char *s, char *t) { while((*t=*s)!='\0') { s++; t++; } } char* strsave(char *s) { char *p; int i=strlen(s)+1; p= (char*) malloc(i); if((p!=NULL)) strcpy2(p,s); return p; } int main() { printf("Enter string for strcpy1 >"); char s[maxline], t[maxline]; getline(s,maxline); strcpy1(s,t); printf("inp.string=%s\nout.string=%s\n",s,t); printf("Enter string for strcpy2 >"); getline(s,maxline); strcpy2(&s[0],&t[0]); printf("inp.string=%s\nout.string=%s\n",s,t); printf("Enter string for strsave >"); getline(s,maxline); char*p=strsave(&s[0]); printf("Saved string=%s\n",p); _getch(); } |