我尝试了创建和开放系统调用.两者都以同样的方式工作,我无法预测它们之间的差异.我阅读了手册页.它显示"打开可以打开设备专用文件,但创建无法创建它们".我不明白什么是特殊文件.
这是我的代码,
我正在尝试使用creat系统调用来读/写文件.
#include<stdio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<unistd.h>
#include<errno.h>
#include<stdlib.h>
int main()
{
int fd;
int written;
int bytes_read;
char buf[]="Hello! Everybody";
char out[10];
printf("Buffer String : %s\n",buf);
fd=creat("output",S_IRWXU);
if( -1 == fd)
{
perror("\nError opening output file");
exit(0);
}
written=write(fd,buf,5);
if( -1 == written)
{
perror("\nFile Write Error");
exit(0);
}
close(fd);
fd=creat("output",S_IRWXU);
if( -1 == fd)
{
perror("\nfile read error\n");
exit(0);
}
bytes_read=read(fd,out,20);
printf("\n-->%s\n",out);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在"输出"文件中打印了内容"Hello".文件已成功创建.但内容是空的
可能重复:
与float文字的float比较中的奇怪输出
这是代码
#include<stdio.h>
int main()
{
float a=0.3;
if(a==0.3)
printf("Hello World!");
else
printf("Stack Overflow");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我期望输出为"Hello World".但我得到了"堆栈溢出".为什么我没有得到"Hello World"?
if情况有什么不对吗?
可能重复:
编译器正在创建额外的类文件,其中包含$
我正在使用Netbeans设计一个java应用程序,我在其中使用Java Swing,因此除了Java源文件之外,我将有.form文件,其中包含有关Java表单的描述.
在src diectory中,我有3个文件,比如
Downloader.java
DownloadCore.java
Downloader.form
Run Code Online (Sandbox Code Playgroud)
现在,如果我使用命令提示符(.ie而不使用Netbeans)手动编译它们,那么我会得到很多.class文件,比如
DownloadCore.class
Downloader$1.class
Downloader$10.class
Downloader$11.class
Downloader$12$1.class
Downloader$12.class
Downloader$2.class
Downloader$3.class
Downloader$4.class
Downloader$5.class
Downloader$6.class
Downloader$7.class
Downloader$8.class
Downloader$9.class
Downloader.class
Run Code Online (Sandbox Code Playgroud)
我想知道为什么JVM创建了这么多.class文件,其中我只有2个.java文件,所以它不应该单独创建2个.class文件.为什么需要它?
提前致谢
我想在C中创建一个链表,我的代码如下.
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int data;
struct node *next;
}node_t;
void insert_into_list(node_t *,int);
void print_list(node_t *);
node_t *create_node(int );
void insert_into_list(node_t *head, int value){
node_t *temp ;
temp = create_node(value);
if(head == NULL){
printf("Inserting node for the first time\n");
head = temp;
}else {
head->next = temp;
}
}
void print_list(node_t *head){
node_t *current = head;
while(current!=NULL){
printf("%d----->",current->data);
current = current->next;
}
printf("NULL");
}
node_t *create_node(int value){
node_t *new_node = malloc(sizeof(node_t));
if(new_node==NULL){
printf("Memory allocation failed …Run Code Online (Sandbox Code Playgroud)