Created
December 23, 2024 20:01
-
-
Save webgtx/5635f05b388efdaa2ee10b3c0f9c3fb6 to your computer and use it in GitHub Desktop.
How to remove newline from the string in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define BUFFER_SIZE 512 | |
int main(void) | |
{ | |
char* string = malloc(sizeof(char) * BUFFER_SIZE); | |
if (!string) return 1; | |
strcpy(string, "pneumenoultramicroscopicsilicovolcanoconiosis\n"); | |
// Remove new line from the string | |
string[strcspn(string, "\n")] = '\0'; | |
puts(string); | |
free(string); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment