c语言学习心得

 enum {jan=0,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec};
 int yearearn,monthearn;
 int n;
 for(yearearn=0,n=0;n<=11;n++)
 {
 switch(n)
 {
 case jan:printf("january:\n");break;
 case feb:printf("february:\n");break;/////使用枚举类型。。

写程序时要淡定,不要因为小错误而慌张,认真检查,找出错误,改正,完善。

c/c++中只能控制输出的格式,而不能控制输入的格式,         
  scanf("%6.3f")       cin>>setw(4)........都是错的。

四舍五入标准函数式:float  b;int  a; a=(b+0.5)

break  —— 终止循环,不再执行该循环。
return  —— 终止函数
scanf  —— {,&n}除了字符串为{,str}外
随机数  —— rand()%n
continue  —— 用于跳过本次循环余下的语句,转向下一次循环

位运算
左移一位相当于乘以10倍(或2倍)-------11——》110
因此:110<<1==1100, 111000>>2==110
二进制中左移n位,相当于乘以2^n.


数组的输入是:两个元素之间空格

i=a>b?a:b
 

定义宏时 #define max x>y?x:y
使用是max;


fatal error C1004: unexpected end of file found 的错误原因为少了花括号'}'。
  
注意数据类型不可搞错。

最大公约数 int d(int a,int b){int r;while((r=a%b)!=0){a=b;b=r;}return b;}
最小公倍数int m(int a,int b){int x;x=d(a,b);return (a*b)/x;}
交换顺序 {t=a;a=b;b=t;}


cannot open Debug 原因是有一个c语言程序在运行,没有关闭。


error C2143: syntax error : missing ']' before '['
 error C2133: 'end' : unknown size
 error C2664: 'gets' : cannot convert parameter 1 from 'char [][80]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
 error C2664: 'gets' : cannot convert parameter 1 from 'char [][80]' to 'char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
错误原因:end[[80]

error C2059: syntax error : '}'
错误原因:do{while(1);}

 

Compiling...
指针方式调用函数的程序.cpp
error C2440: '=' : cannot convert from 'float (__cdecl *)(float [],int)' to 'float (__cdecl *)(void)'This conversion requires a reinterpret_cast, a C-style cast or function-style cast
error C2197: 'float (__cdecl *)(void)' : too many actual parameters
指针方式调用函数的程序.exe - 2 error(s), 0 warning(s)
--**&&**--错误原因:{float sumf,sump;
float a[M]={11,2,-3,4.5,69,7,80,780};
float (*p)();
float max(float a[],int n);
应改为float sumf,sump;
float a[M]={11,2,-3,4.5,69,7,80,780};
float (*p)(float *,int);
float max(float a[],int n);


若没有括号,则for仅包括靠近它的语句。
for (;*p!='\0';p++,q++){ *q=*p;    };*q='\0';等价于for(;*p!='\0';p++,q++)*q=*p;*q='\0';


动态数组解决了传统静态数组的缺陷。
结构体(将一些基本数据类型组合在一起)可以表示一些基本数据类型无法表示的复杂的事物
(*pt).x=pt->x;
pt=&p;
*pt=p;
定义时*pt=&p;


error C2448: '<Unknown>' : function-style initializer appears to be a function definition
问题出在:定义与引用时函数的参数应相同。如: 声明时void list(struct stud_type student);
引用时若void list(student)则出现错误。应该void list(struct stud_type student).

void list(student)
struct stud_type student;//应去掉‘;’。
{
 printf("%-20s%8ld%6d%3c\n",student.name,student.num,student.age,student.sex);
}

fatal error C1004: unexpected end of file found

 

error C2039: 'im' : is not a member of 'complex'
原因是struct complex
{float re,m;
};少了‘i’。应改为struct complex{float re,im;};


c++中也可以用<conio.h>getch();


setw(n)包含在#include<iomanip.h>头文件中。

 

Linking...
LINK : fatal error LNK1168: cannot open Debug/用c++求平均成绩的程序.exe for writing
执行 link.exe 时出错.
原因是。。。。:有另外的c程序在运行,没有关闭。


putchar('字符')-----------------puts("字符串")

你可能感兴趣的:(原因,c语言常见错误)