How to read string with spaces using scanf() function in C

1 Answer

0 votes
#include <stdio.h>

int main() {
	char s[40];
	
	scanf("%[^\n]", s);
	
	printf("%s\n", s);
	
	return 0;
}

  
/*
run:

c c++ java php
c c++ java php

*/

 



answered Jul 10, 2019 by avibootz

Related questions

1 answer 259 views
1 answer 309 views
2 answers 308 views
308 views asked Sep 21, 2021 by avibootz
1 answer 240 views
240 views asked Sep 21, 2021 by avibootz
1 answer 197 views
...