C#读写文件

C#读写文件的方法:

C#中,在含有转义字符的 字符串前加@可以避免使用转义字符

使用前要using System.IO;

StreamReader reader = new StreamReader(@"E:/main.c", Encoding.Default);            
string line;
while ((line = reader.ReadLine()) != null)
{
    Console.WriteLine(line);
}
reader.Close();
// 参数改为false可以直接重写文件
StreamWriter writer = new StreamWriter(@"E:/main.c", true, Encoding.Default);
writer.WriteLine("ok..");
writer.Close();

C语言拆分字符串strtok

C语言拆分字符串strtok函数

Example
/* STRTOK.C: In this program, a loop uses strtok
 * to print all the tokens (separated by commas
 * or blanks) in the string named "string".
 */
#include <string.h>
#include <stdio.h>
char string[] = "A string/tof ,,tokens/nand some  more tokens";
char seps[]   = " ,/t/n";
char *token;
void main( void )
{
   printf( "%s/n/nTokens:/n", string );
   /* Establish string and get the first token: */
   token = strtok( string, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      printf( " %s/n", token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }
}