fgets giving me null

#include <stdio.h> #include <stdlib.h> int main () { int firstDigit; char *firstNumber = 0; char operator; int secondDigit; char *secondNumber = 0; printf("digit "); scanf("%d *[^\n]", &firstDigit); fgets(firstNumber, firstDigit, stdin); printf("%s \n", firstNumber); } The code here gives me null as firstNumber while it clearly should just be a string. here is the results of… Read More fgets giving me null

Bad file descriptor fgets

I’m trying to create a file to send information to another process. But when I reach the send_file function, I get –>Error in fgets():: Bad file descriptor. Can someone help me address this matter, please? I’m stuck. #include <stdlib.h> #include <stdio.h> void send_file(FILE *fp, int sockfd){ char data[SIZE] = {0}; if (fgets(data, SIZE, fp) ==… Read More Bad file descriptor fgets

I am trying to load words from a text file into a binary search tree

I am trying to load words from a text file into a binary search tree. Each line of the file contains one word. #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct node node; struct node { node *left, *right; char *key; }; node *newnode(char *key) { node *n = malloc(sizeof(node)); n->key = malloc(sizeof(key)); strcpy(n->key, key);… Read More I am trying to load words from a text file into a binary search tree