Skip to content

Instantly share code, notes, and snippets.

@webgtx
Created December 23, 2024 20:01
Show Gist options
  • Save webgtx/5635f05b388efdaa2ee10b3c0f9c3fb6 to your computer and use it in GitHub Desktop.
Save webgtx/5635f05b388efdaa2ee10b3c0f9c3fb6 to your computer and use it in GitHub Desktop.

Revisions

  1. webgtx created this gist Dec 23, 2024.
    18 changes: 18 additions & 0 deletions howtoremovenewlinefromthestring.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #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);
    }