#include <stdio.h>#include<conio.h>
#include<math.h>
#include <string.h>
#include<malloc.h>
#include<stdlib.h>
void main(){
FILE*f_pic,*f_file,*f_finish;
char ch,pic_name[20],file_name[20],finish_name[20];
printf("请输入需要合成的图片和文件的名称:\n\n");
printf("图片:");
scanf("%s",pic_name);
printf("文件:");
scanf("%s",file_name);
printf("生成为:");
scanf("%s",finish_name);
if(!(f_pic=fopen(pic_name,"rb")))
{
printf("cannot open the picture %s!",pic_name);
return;
}
if(!(f_file=fopen(file_name,"rb")))
{
printf("cannot open the picture %s!",file_name);
return;
}
if(!(f_file=fopen(finish_name,"wb+")))
{
printf("cannot open the file %s !",finish_name);
return;
}
while(!(feof(f_pic))) {
ch=fgetc(f_pic);
fputc(ch,f_finish); //这里就提示错误 C4700: 使用了未初始化的局部变量“f_finish”
}
fclose(f_pic);
while(!(feof(f_file))) {
ch=fgetc(f_file);
fputc(ch,f_finish);
}
fclose(f_file);
fclose(f_finish);
system("pause");
return ;
}
显然,I和y都是局部的变量。I的初值是0,但是y是未初始化的局部变量。
如:
IntI=0;Inty;
(;我< y;我+ +){
//……
}
}
扩展资料:
在c++中初始化的全局变量在编译时存储在数据段中,而未初始化的全局变量则存储在BSS段中。这样做的原因是data部分中的变量需要分配空间来将它们的值存储在编译后的文件中,
不初始化保存变量(或初始化为0的静态变量或全局变量),其默认值为0。没有必要在data部分存储其值都为0的变量。但是,BSS部分只保留给未初始化的全局变量和局部静态变量。
但是,这些变量在程序执行时占用内存空间,因此可执行程序必须记录这些变量在BSS段中占用多少空间。