void add_recursive(char *path, char **ent, int nfil) { char **e; char *buff; int i; int item = 0; int nf; for(i=0; i<nfil; i++) { if(!is_dir(path, ent[i])) { buff = mystrcat(path,ent[i],1); if(add(&playlist_h, buff, &playlist_t)) { if(p_p == -1) p_p++; nsongs++; } free(buff); } else { // is a dir if(strncmp(ent[i], ".." ,2) != 0) { // d'oh! buff = mystrcat(path, ent[i], 1); if(e = get_dir(buff, &nf)) { add_recursive(buff, e, nf); while(item < nf) { free(e[item++]); } free(e); } free(buff); } } } }
static void _populate(char *base, int *cnt, int max) { char buf[64], *p; int fd; while (*cnt < max) { int i = rand() % (sizeof(selectors)/sizeof(selectors[0])); switch (selectors[i]) { case S_FILE: /* Create a file */ snprintf(buf,sizeof buf,"%x",rand()); p = mystrcat(base,"/",buf); fd = open(p,O_WRONLY|O_CREAT|O_EXCL,0666); free(p); if (fd == -1) continue; snprintf(buf,sizeof buf,"%d", rand() % CLUSTER); write(fd,buf,strlen(buf)); close(fd); ++(*cnt); break; case S_DIR: /* Create a directory */ snprintf(buf,sizeof buf,"%x",rand()); p = mystrcat(base,"/",buf); fd = mkdir(p,0777); if (fd == 0) { ++(*cnt); _populate(p, cnt, max); } free(p); break; case S_END: return; } } }
void prog9() { char str1[80] = "This is a test"; char str2[80] = "0123456789"; mystrcat(str1, str2, 5); // concatenate 5 chars cout << str1 << '\n'; strcpy(str1, "This is a test"); // reset str1 mystrcat(str1, str2); // concatenate entire string cout << str1 << '\n'; }
int main() { char str1[100] = "Matt"; char *str2 = "Shaffer"; mystrcat(str1, " "); mystrcat(str1, str2); printf("%s\n", str1); return 0; }
tCString pathcat(tCString dir, tCString filename) { size_t len = strlen(dir); char last = *(dir + len - 1); if (last == PATH_DELIMITER_C) return (tCString)mystrcat(2, dir, filename); if (*dir) return (tCString)mystrcat(3, dir, PATH_DELIMITER_S, filename); else return mystrdup(filename); }
int main() { char dest[100] = "MARK"; char src[] = "TWAIN"; printf("%s\n", mystrcat(dest, src)); dest[4] = '\0'; printf("%s\n", mystrcat( mystrcat(dest, " "), src)); return 0; }
int main() { char a[128] = "asdfdsf"; char *b = "tt"; char p[128]; p[0] = '\0'; mystrcat(p, mystrcat(a, b)); // mystrcat(p, b); puts(p); // puts(p); return 0; }
int main(void) { char szPath[128] = { 0 }; char *pszEnd = NULL; //대상 메모리에 문자열을 붙인다. pszEnd = mystrcat(szPath, "C:\\Program Files\\"); //앞서 반환 받은 주소를 첫 번째 인수로 호출해 문자열을 붙인다. pszEnd = mystrcat(pszEnd, "CHS\\"); pszEnd = mystrcat(pszEnd, "C programming"); puts(szPath); return 0; }
main() { char s[] = "Hello"; char t[] = " There"; mystrcat(s, t); printf("%s\n", s); }
int main(){ char s[30] = "hello"; char * s1 = ",world"; printf("%s\n",mystrcat(s,s1)); printf("%s\n",strcat(s,s1)); return 0; }
int main() { char s[MAXLENGTH] = "Hello, "; char t[MAXLENGTH] = "world!"; mystrcat(s, t); printf("%s\n", s); }
/** * @fn void mystrcat_test(char * s1, char * s2, char * expected) * @brief unit test */ void mystrcat_test(char * s1, char * s2, char * expected) { /// 쉬운 비교를 위해서 string.h > strcmp 를 사용하도록 한다. /// 만약 두 string이 같다면 strcmp는 0을 리턴한다. printf("[%s] strcat(\"%s\", \"%s\") should return \"%s\"\n", !strcmp( mystrcat(s1,s2), expected) ? "SUCCESS" : "FAILED", s1, s2, expected ); }
int main() { char buffer[100]; sprintf(buffer, "Hello, "); mystrcat(buffer, "world!"); printf("%s\n", buffer); return 0; }
int main() { char str[20] = "abcde"; char *p_str = mystrcat(str, "xyz"); printf("%s\n", str); printf("%s\n", p_str); return 0; }
void test3() { char a[200]; char * b; mystrcpy(a, "Hello world"); b = mystrcat(a, ", CS240 C Programming"); b = mystrcat(a, ", This is a great course"); printf("\"%s\"\n", a); printf("\"%s\"\n", b); mystrcpy(a, ""); b = mystrcat(a, ""); b = mystrcat(b, "Hello"); printf("\"%s\"\n", a); printf("\"%s\"\n", b); }
int send_recv(int acc, int child_no){ char buf[512], *ptr; ssize_t len; if((len = recv(acc, buf, sizeof(buf), 0)) == -1){ perror("recv"); return(-1); } if(len == 0){ fprintf(stderr, "recv:EOF\n"); return(-1); } buf[len] = '\0'; if((ptr = strpbrk(buf, "\r\n")) != NULL){ *ptr = '\0'; } fprintf(stderr, "[client]%s\n", buf); mystrcat(buf, ":OK\r\n", sizeof(buf)); len = (ssize_t) strlen(buf); if((len = send(acc, buf, (size_t) len, 0)) == -1){ perror("send"); return(-1); } return(0); }
short SaveLangFileAs( char *filename ) { char fileWithPath[1024]; // Check the exe directory first - as this is where users should have their lang directory GetLangV41File( fileWithPath, gPath, PATHSEPSTR, 0 ); if ( ValidatePath( fileWithPath ) ) { // Now check for a lang directory which is located back a directory - this where we have our lang directory GetLangV41File( fileWithPath, gPath, PATHBACKDIR, 0 ); } if ( ValidatePath( fileWithPath ) ) { // Try the current directory - basically, a last resort... GetLangV41File( fileWithPath, 0, 0, 0 ); } if ( GetLangSaveFolderName( fileWithPath, filename ) ) { ReadNewLangStringsFromLangList(); char *pos; pos = strstri( fileWithPath, LANG_EXT ); if ( !pos ) mystrcat( fileWithPath, LANG_EXT ); if ( SaveNewLangStringsToLangFile( fileWithPath ) ) { FileFromPath( fileWithPath, MyPrefStruct.language ); strcpyuntil( MyPrefStruct.language, MyPrefStruct.language, '.' ); return 1; } } return 0; }
//session 1 int main(int argc, char*argv[]) { for(int i=0;i<argc;i++) { //Check my name in the argument if(mystrcmp("Chen",argv[i])==0) { //copy"Hello" to the array char hi[30]; mystrcpy(hi,"Hello, "); //put my name after hello mystrcat(hi,argv[i]); printf("%s\n",hi); } else{ printf("%s\n",argv[i]); } } //session 6 int a[10]; for(int i=0; i<10;i++) { a[i]=i*i; printf("%d\n", *(a+i)); } }
void mkfile(const char *dir,const char *fn,const char *data) { char *p = mystrcat(dir,"/",fn); int fd = open(p,O_WRONLY|O_CREAT|O_EXCL,0666); free(p); write(fd,data,strlen(data)); close(fd); }
static void do_dedup(struct fs_dat *fs,ino_t *inos,int icnt,struct stat *stp,void *ext) { struct dedup_stats *s = (struct dedup_stats *)ext; int i; char **fpt, *basepath, *vpath; struct stat stb; idx = fs->itab; qsort(inos,icnt,sizeof(ino_t),dedup_cmp); fpt = inodetab_get(fs->itab,inos[0],&stp->st_mtime); stb.st_ino = inos[0]; if (gopts.verbose > 1) { printf("- (%llx):u=%d g=%d m=%03o (%s):%s\n", (long long)inos[0], stp->st_uid, stp->st_gid, stp->st_mode, make_human_readable_str(stp->st_size,0,0), *fpt); } if (fpt == NULL || *fpt==NULL) fatal(ENOENT,"Missing i-node %llx",(long long)inos[0]); basepath = mystrcat(fs->root,"/",*fpt,NULL); for (i = 1; i < icnt; i++) { fpt = inodetab_get(fs->itab,inos[i],&stp->st_mtime); if (fpt == NULL || *fpt==NULL) fatal(ENOENT,"Missing i-node %llx",(long long)inos[i]); while (*fpt) { if (gopts.verbose > 1) { printf(" -> (%llx):%s\n", (long long)inos[i], *fpt); } vpath = mystrcat(fs->root,"/",*(fpt++),NULL); if (stb.st_ino != inos[i]) { /* Compute statistics... */ if (lstat(vpath,&stb) == -1) errormsg("lstat(%s)",vpath); s->blocks += stb.st_blocks; } s->files++; if (!gopts.dryrun) { if (unlink(vpath)==-1) errormsg("unlink(%s)",vpath); if (link(basepath,vpath)==-1) errormsg("link(%s->%s)",basepath,vpath); } else { if (gopts.verbose > 2) { fprintf(stderr,"Linking %s -> %s\n", vpath, basepath); } } free(vpath); } } free(basepath); }
int main() { char a[200],b[100]; gets(a); gets(b); mystrcat(a,b); puts(a); return 0; }
int main(void) { char str[80] = "hihi"; mystrcat(str, "これはテストです。"); printf(str); return 0; }
static void _hcache_validate_init(struct hcache *cache) { char *vfname; if (cache->validated) return; vfname = mystrcat(cache->path,".validate"); cache->validated = gdbm_open(vfname,0, GDBM_NEWDB, 0666,NULL); if (!cache->validated) fatal(gdbm_errno,"gdbmopen(%s): %s", vfname, gdbm_strerror(gdbm_errno)); free(vfname); }
int main (int argc, char const* argv[]) { char s[1024] = "ni hao"; char *t = "hello, world"; mystrcat(s, t); printf("%s\n", s); getchar(); return 0; }
int main() { char str1[32] = "hello,"; char str2[32] = "world!"; printf("%s\n", mystrcat(str1, str2)); printf("%s\n", str1); return 0; }
int main() { char a[] = "Hello "; char *b = "World"; mystrcat(a,b); printf("%s\r\n",a); return 0; }
struct hcache *hcache_new(const char *base,int type,int len) { struct hcache *cache = (struct hcache *)mymalloc(sizeof(struct hcache)); char *cachefile = mystrcat(base,".hcd"); memset(cache,0,sizeof(struct hcache)); cache->path = cachefile; cache->dbf = gdbm_open(cachefile,0,GDBM_READER,0666,NULL); cache->type = type; cache->hlen = len; return cache; }
int main() { char buf[N]; char *src_1 = "hello"; char *src_2 = "world"; mystrcpy(buf,src_1); puts(buf); mystrcat(buf,src_2); puts(buf); return 0; }
void main() { printf("第52题 编写一个函数fun,它的功能是:实现两个字符串的连接(不使用库函数strcat),即把p2所指的字符串连接到p1所指的字符串后。\n\n"); char str1[100], str2[100]; printf("Input string1: "); gets(str1); printf("Input string2: "); gets(str2); mystrcat(str1, str2); printf("\n\nOutput count: %s \n\n", str1); }
/** * @fn void mystrcat_exec(void) * @todo * ---result--- * warning: this program uses gets(), which is unsafe. * Enter first string : hello * Enter second string : world * result is [hello world] * ------------ * gets()는 위험하다고 한다. fgets로 수정해보자. */ void mystrcat_exec(void) { char foo[100] = {'\0'}; char bar[100] = {'\0'}; printf("Enter first string : "); gets(foo); printf("Enter second string : "); gets(bar); printf("result is [%s]\n", mystrcat(foo, bar) ); }