Hello, I'm a beginner in C language.
#include <stdio.h>
int main(void)
{
int i = 0;
char name[1001];
printf ("What is your name?" : ");
gets(name);
FILE *file = NULL;
file = fopen("your_name.txt", "w");
if (file == NULL)
{
printf("Failed to open file.");
}
else
{
printf ("The file was successfully opened.");
}
while (name[i] != '\0')
{
fputs(name[i], file);
i++;
}
fclose(file);
}
If you look at this code and think about it, it should have the name you entered in your_name, but it's actually made, but there's nothing inside. There is no error, but the warning message is
[Warning] passing argument 1 of 'fputs' makes pointer from integer without a cast
That's what he said. Did I do anything wrong?
c
First, look at the prototype of the fputs function.
int fputs(const char* str, FILE* stream);
The fputs function is a function that writes a string to stream.
It's not a character, it's a string (!).
In other words, you need to insert a pointer to char.
Please modify it as below and try it.
//while (name[i] != '\0')
//{
fputs(name, file);
// // i++;
//}
703 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
542 Unable to install versioned in Google Colab
549 PHP ssh2_scp_send fails to send files as intended
547 Who developed the "avformat-59.dll" that comes with FFmpeg?
547 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.