Signal: segmentation fault (core dumped)

Hello, coding guys,

I am having the error shown in the title, this is the source code:

#include <stdio.h>

void println(str) {
	printf(str + "\n");
}

int main(void) {
  println("Hello World");
  return 0;
}
1 Like

you can’t just concatenate strings with the + operator in C. In this case, there’s no point creating a new function: there is a built-in function puts which adds a new line after the text

Thank you for responding to this @StupidGenius - somehow I missed the OP thread!

This link might also be helpful to teach you how to concatenate strings in C @RixTheTyrunt How to concatenate strings in C: A five minute guide

Do this

#include <stdio.h>

void println(str) {
	printf("%s\n", str);
}

int main(void) {
  println("Hello World");
  return 0;
}
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.