C 2026-11-06 C库函数 - atoi() #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { int val; char str[20]; strcpy(str, "98993489"); val = atoi(str); printf("String value = %s, Int value = %d\n", str, val); strcpy(str, "codingdict.com"); val = atoi(str); printf("String value = %s, Int value = %d\n", str, val); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - atof() #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { float val; char str[20]; strcpy(str, "98993489"); val = atof(str); printf("String value = %s, Float value = %f\n", str, val); strcpy(str, "codingdict.com"); val = atof(str); printf("String value = %s, Float value = %f\n", str, val); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - perror() #include <stdio.h> int main () { FILE *fp; /* first rename if there is any file */ rename("file.txt", "newfile.txt"); /* now let's try to open same file */ fp = fopen("file.txt", "r"); if( fp == NULL ) { perror("Error: "); return(-1); } fclose(fp); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - puts() #include <stdio.h> #include <string.h> int main () { char str1[15]; char str2[15]; strcpy(str1, "codingdict"); strcpy(str2, "compileonline"); puts(str1); puts(str2); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - sscanf() #include <stdio.h> #include <stdlib.h> #include <string.h> int main () { int day, year; char weekday[20], month[20], dtm[100]; strcpy( dtm, "Saturday March 25 1989" ); sscanf( dtm, "%s %s %d %d", weekday, month, &day, &year ); printf("%s %d, %d = %s\n", month, day, year, weekday ); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - fscanf() #include <stdio.h> #include <stdlib.h> int main () { char str1[10], str2[10], str3[10]; int year; FILE * fp; fp = fopen ("file.txt", "w+"); fputs("We are in 2012", fp); rewind(fp); fscanf(fp, "%s %s %s %d", str1, str2, str3, &year); printf("Read String1 |%s|\n", str1 ); printf("Read String2 |%s|\n", str2 ); printf("Read String3 |%s|\n", str3 ); printf("Read Integer |%d|\n", year ); fclose(fp); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - vprintf() #include <stdio.h> #include <stdarg.h> void WriteFrmtd(char *format, ...) { va_list args; va_start(args, format); vprintf(format, args); va_end(args); } int main () { WriteFrmtd("%d variable argument\n", 1); WriteFrmtd("%d variable %s\n", 2, "arguments"); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - vsprintf() #include <stdio.h> #include <stdarg.h> char buffer[80]; int vspfunc(char *format, ...) { va_list aptr; int ret; va_start(aptr, format); ret = vsprintf(buffer, format, aptr); va_end(aptr); return(ret); } int main () { int i = 5; float f = 27.0; char str[50] = "tutoriaspoint.com"; vspfunc("%d %f %s", i, f, str); printf("%s\n", buffer); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - sprintf() #include <stdio.h> #include <math.h> int main () { char str[80]; sprintf(str, "Value of Pi = %f", M_PI); puts(str); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - printf() #include <stdio.h> int main () { int ch; for( ch = 75 ; ch <= 100; ch++ ) { printf("ASCII value = %d, Character = %c\n", ch , ch ); } return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - tmpnam() #include <stdio.h> int main () { char buffer[L_tmpnam]; char *ptr; tmpnam(buffer); printf("Temporary name 1: %s\n", buffer); ptr = tmpnam(NULL); printf("Temporary name 2: %s\n", ptr); return(0); }
阅读全文 ↗ C 2026-11-06 C库函数 - tmpfile() #include <stdio.h> int main () { FILE *fp; fp = tmpfile(); printf("Temporary file created\n"); /* you can use tmp file here */ fclose(fp); return(0); }
阅读全文 ↗