源码:
# include <stdio.h>
/* 宏定义 */
# define MAX 100
# define LEN 80
/* 一个非常简单的文本编辑器 */
int main()
{
char text[MAX][LEN]; // 定义字符型数组
register int t, i, j; /* 定义三个寄存器变量 */
/* 逐行输入字符串 */
for(t=0; t<MAX; t++)
{
printf("%d: ", t);
gets(text[t]);
if(!text[t][0])
break; /* 空行退出 */
}
/* 按行,逐个字符输出字符串 */
for(i=0; i<t; i++)
{
for(j=0; text[i][j]; j++)
putchar(text[ ......
源码:
# include <stdio.h>
int main()
{
/* 有尺寸 */
/* 一维整形数组初始化 */
int array1[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
/* 一维字符型数组初始化,最后一个元素自动添加为‘/0’ */
char array2[13] = "How are you!"; /* 方式一 */
char array3[13] = {'H','o','w',' ','a','r','e',' ','y','o','u','!'}; /* 方式二 */
/* 二维整形数组初始化 */
int array4[4][4] =
{
12, 18, 6, 25,
23, 10, 32, 16,
25, 63, 1, 63,
0, 0, 27, 98
}; /* 矩阵的形式 */
/* 无尺寸 */
&nb ......
源码:
/* 学生成绩查询系统 */
# include <stdio.h>
# include <stdlib.h>
int main( )
{
int select;
int i, j;
int score[5][7];
int average = 0;
int sum = 0;
do{
printf("本程序有4项功能:\n");
printf(" 1. 根据学号查询学生成绩\n");
printf(" 2. 根据考试号统计成绩\n") ;
printf(" 3. 根据考试号和学号查询成绩\n");
printf(" 4. 成绩录入\n");
printf(" 0. 退出\n");
printf(" 请输入选择(0 - 4): ");
scanf("%d", &select);
switch ......
源码:
# include <stdio.h>
/* 子函数声明 */
int square(int x); // 实现求平方值的子函数
int cube(int y); // 实现求立方值的子函数
int main()
{
int m = 12;
int n = 4;
printf("%d %d\n", square(m), m);
printf("%d %d\n", cube(n), n);
return 0;
}
int square(int x)
{
x = x*x;
return x;
}
int cube(int y)
{
y = y*y*y;
return y;
} ......
源码:
# include <stdio.h>
void swap(int *x, int *y);
int main()
{
int i, j;
i = 12;
j = 36;
printf("i and j before swapping: %d %d\n", i, j);
swap(&i, &j); // 传递变量i和j的地址,深刻理解此时:&i为变量的地址,而i为变量(值)
// 调用swap函数的传递过程为:x=&i ; y=&j ;
printf("i and j after swapping: %d %d\n", i, j);
return 0;
}
void swap(int *x, int *y) // 深刻理解此时:*x为变量(值)而x为指针(地址)
{
int temp;
temp = *x; /* 存储变量x的值 */
*x = *y; /* 将y的值放入到x中 */
*y = temp; /* 将x的值放入到y中 */
}
......
C Sharp(C#)中如何删除文件(文件夹)
直接删除:
using System.IO;
...
string filePath = @"D:\...\xxx.xxx";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
else
{
Console.WriteLine("file not exist.");
Console.ReadLine();
}
删除到回收站:
using System.Runtime.InteropServices;
namespace CSharp
{
class Program
{
private const int FO_DELETE = 3;
private const int FOF_ALLOWUNDO = 0x40;
private const int FOF_NOCONFIRMATION = 0x0010;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)]
public int wFunc;
public string pfrom;
public string pTo;
public short fFlags;
[MarshalAs(Unmanage ......
C Sharp(C#)中如何删除文件(文件夹)
直接删除:
using System.IO;
...
string filePath = @"D:\...\xxx.xxx";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
else
{
Console.WriteLine("file not exist.");
Console.ReadLine();
}
删除到回收站:
using System.Runtime.InteropServices;
namespace CSharp
{
class Program
{
private const int FO_DELETE = 3;
private const int FOF_ALLOWUNDO = 0x40;
private const int FOF_NOCONFIRMATION = 0x0010;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 1)]
public struct SHFILEOPSTRUCT
{
public IntPtr hwnd;
[MarshalAs(UnmanagedType.U4)]
public int wFunc;
public string pfrom;
public string pTo;
public short fFlags;
[MarshalAs(Unmanage ......