Re: [問題] 請問這段fopen() 該怎麼改
※ 引述《homal.bbs@ptt.cc (\冏/)》之銘言:
> 我希望由使用者輸入檔名, 像: 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: uranus@it.muds.net
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"的狂狷不馴;屬於年少的輕狂色彩 ◎
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章