看板Programming
标 题Re: [问题] 请问这段fopen() 该怎麽改
发信站政大狂狷年少 (Thu Nov 16 15:32:07 2006)
转信站ptt!ctu-reader!ctu-peer!news.nctu!netnews.csie.nctu!news.cs.nthu!WHSHS
※ 引述《[email protected] (\冏/)》之铭言:
> 我希望由使用者输入档名, 像: manual.txt
> 然後,我就能用fopen 开启这个档案.
> 我的写法是这样:
> char name[16], *p;
> fgets(name,sizeof(name),stdin);
> p=name;
> FILE fp;
> fp=fopen(p,"w");
> 不过 fopen 这行出现错误 incompatible types in assignment
这个错误讯息的意思是「在设值动作中存在不相容的型别」,
assignment 就是指设值的动作,
也就是 x = y 这样的算式行为,
换句话说它就是在跟你讲:x 跟 y 的 type 是不相容的,
这时你应当检查 fp 的 type,
并查询 C library 的手册以了解 fopen() 的 return type 为何,
这样就可以解决问题了。
如果你还不会查 library 手册,
我可以先贴给你关键部分的内容,
但希望你还是要尽快学会怎麽去查:
FOPEN(3) FreeBSD Library Functions Manual FOPEN(3)
NAME
fopen, fdopen, freopen -- stream open functions
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdio.h>
FILE *
fopen(const char * restrict path, const char * restrict mode);
--
Name: Tseng, Ling-hua E-mail Address:
[email protected]
School: National Tsing Hua University Department: Computer Science
Interesting: C++, Compiler, PL/PD, OS, VM, Large-scale software design
Researching: Software pipelining for VLIW architectures
Homepage:
https://it.muds.net/~uranus
--
╔═══╗ ┼────────────────────────╮
║狂狷 ║ │
* Origin:[ 狂 狷 年 少 ] whshs.cs.nccu.edu.tw ╰─╮
║ 年少║ ┼╮
< IP:140.119.164.252 > ╰─╮
╚╦═╦╝ ╰
* From:61-230-216-180.dynamic.hinet.net
─╨─╨─ KGBBS ─ ◎ 遨翔"BBS"的狂狷不驯;属於年少的轻狂色彩 ◎