user-0 提问: 汉字转换拼音

回复:
user: user-1
content: #include <stdio.h> #include <string.h> #define MAXLEN 1000 char ln[MAXLEN]; FILE *f; int i,z; int b,n,L; int main(int argc,char **argv) {     if (argc<2) {         printf("Usage:%s fullpathfilename.ext\nget total blank/non-blank/total linenumbers.\n",argv[0]);         return 1;     }     f=fopen(argv[1],"r");     if (NULL==f) {         printf("Can not open file [%s]!\n",argv[1]);         return 2;     }     z=0;     b=0;     n=0;     L=0;     while (1) {         if (NULL==fgets(ln,MAXLEN,f)) break;         L=strlen(ln);         if ('\n'==ln[L-1]) {             if (0==z) {                 for (i=0;i<L-1;i++) {                     if (!(' '==ln[i] || '\t'==ln[i])) break;                 }                 if (i<L-1) z=1;//当前行不是空行             }             if (0==z) b++; else n++;             z=0;         } else {             if (0==z) {                 for (i=0;i<L;i++) {                     if (!(' '==ln[i] || '\t'==ln[i])) break;                 }                 if (i<L) z=1;//当前行不是空行             }         }     }     fclose(f);     if (L>0 && '\n'!=ln[L-1]) {         if (0==z) b++; else n++;//最后一行末尾无'\n'也计算     }     printf("File:[%s] total blank/non-blank/total linenumbers is %d/%d/%d\n",argv[1],b,n,b+n);     return 0; }

user: user-1
content: fgets, fgetws Get a string from a stream.  char *fgets( char *string, int n, FILE *stream );  wchar_t *fgetws( wchar_t *string, int n, FILE *stream );  Function Required Header Compatibility  fgets <stdio.h> ANSI, Win 95, Win NT  fgetws <stdio.h> or <wchar.h> ANSI, Win 95, Win NT    For additional compatibility information, see Compatibility in the Introduction.  Libraries  LIBC.LIB Single thread static library, retail version  LIBCMT.LIB Multithread static library, retail version  MSVCRT.LIB Import library for MSVCRT.DLL, retail version    Return Value  Each of these functions returns string. NULL is returned to indicate an error or an end-of-file condition. Use feof or ferror to determine whether an error occurred.  Parameters  string  Storage location for data  n  Maximum number of characters to read  stream  Pointer to FILE structure  Remarks  The fgets function reads a string from the input stream argument and stores it in string. fgets reads characters from the current stream position to and including the first newline character, to the end of the stream, or until the number of characters read is equal to n – 1, whichever comes first. The result stored in string is appended with a null character. The newline character, if read, is included in the string.   fgets is similar to the gets function; however, gets replaces the newline character with NULL. fgetws is a wide-character version of fgets.   fgetws reads the wide-character argument string as a multibyte-character string or a wide-character string according to whether stream is opened in text mode or binary mode, respectively. For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes.  Generic-Text Routine Mappings  TCHAR.H Routine  _UNICODE & _MBCS Not Defined _MBCS Defined _UNICODE Defined  _fgetts fgets fgets fgetws    Example  /* FGETS.C: This program uses fgets to display  * a line from a file on the screen.  */  #include <stdio.h>  void main( void ) {    FILE *stream;    char line[100];     if( (stream = fopen( "fgets.c", "r" )) != NULL )    {       if( fgets( line, 100, stream ) == NULL)          printf( "fgets error\n" );       else          printf( "%s", line);       fclose( stream );    } }   Output  /* FGETS.C: This program uses fgets to display     Stream I/O Routines  See Also   fputs, gets, puts

user: user-0
content: 如果我要是用字符串数组做呢   是不是在Fgets读取时在后面自动加上了'\0'

user: user-1
content: 引用 5 楼 beiye90 的回复:[quote=引用 3 楼 zhao4zhong1 的回复:]     char a[7000][100];     char b[1000];      if ((cp=fopen("常用汉字拼音对照表.txt","r"))==NULL) {         printf("\n\n\t\t    没有对照表！\n\n");         return;     }     while (1) {         if (NULL==fgets(a[i],100,cp)) break;         if ('\n'==a[i][strlen(a[i])-1]) a[i][strlen(a[i])-1]=0;         i++;         if (i>=7000) break;     }  我做时 把这个a[i][strlen(a[i])-1]=0;写成了a[i][strlen(a[i])-1]='\0'; 为什么不行？[/quote] 你前面少条件if ('\n'==a[i][strlen(a[i])-1]) 啊。

user: user-0
content: 引用 3 楼 zhao4zhong1 的回复:    char a[7000][100];     char b[1000];      if ((cp=fopen("常用汉字拼音对照表.txt","r"))==NULL) {         printf("\n\n\t\t    没有对照表！\n\n");         return;     }     while (1) {         if (NULL==fgets(a[i],100,cp)) break;         if ('\n'==a[i][strlen(a[i])-1]) a[i][strlen(a[i])-1]=0;         i++;         if (i>=7000) break;     }  我做时 把这个a[i][strlen(a[i])-1]=0;写成了a[i][strlen(a[i])-1]='\0'; 为什么不行？

user: user-0
content: 我做时 把这个a[i][strlen(a[i])-1]=0;写成了a[i][strlen(a[i])-1]='\0'; 为什么不行？

user: user-1
content: char a[7000][100];     char b[1000];      if ((cp=fopen("常用汉字拼音对照表.txt","r"))==NULL) {         printf("\n\n\t\t    没有对照表！\n\n");         return;     }     while (1) {         if (NULL==fgets(a[i],100,cp)) break;         if ('\n'==a[i][strlen(a[i])-1]) a[i][strlen(a[i])-1]=0;         i++;         if (i>=7000) break;     }

user: user-0
content: 还是换行啊！

user: user-1
content: char a[7000][100];     char b[1000];     if((cp=fopen("常用汉字拼音对照表.txt","r"))==NULL)     printf("\n\n\t\t    没有对照表！\n\n");     while (!feof(cp))     {         fgets(a[i++],100,cp);