How to print a string without using printf() and puts() in C

4 Answers

0 votes
#include <stdio.h>

int main(void)
{
  char *s = "c c++ c# java python php";
    
  fputs(s, stdout);
}



/*
run:
 
c c++ c# java python php

*/

 



answered Sep 28, 2017 by avibootz
edited Nov 8, 2024 by avibootz
0 votes
#include <stdio.h>

int main(void)
{
  char *s = "c c++ c# java python php";
    
  fprintf(stdout, "%s", s);
}



/*
run:
 
c c++ c# java python php

*/

 



answered Sep 28, 2017 by avibootz
edited Nov 8, 2024 by avibootz
0 votes
#include <stdio.h> 
#include <string.h> 

int main(void)
{
  char *s = "c c++ c# java python php";
  int len = strlen(s);
    
  for (int i = 0; i < len; i++) 
      putc(s[i], stdout);
}



/*
run:
 
c c++ c# java python php

*/

 



answered Sep 28, 2017 by avibootz
edited Nov 8, 2024 by avibootz
0 votes
#include <stdio.h> 
#include <string.h> 
#include <unistd.h>

int main(void)
{
  char *s = "c c++ c# java python php";
    
  write(1, s, strlen(s));
}



/*
run:
 
c c++ c# java python php

*/

 



answered Sep 28, 2017 by avibootz
edited Nov 8, 2024 by avibootz

Related questions

1 answer 239 views
1 answer 171 views
171 views asked Dec 29, 2023 by avibootz
1 answer 159 views
1 answer 211 views
1 answer 186 views
1 answer 160 views
1 answer 141 views
141 views asked Jun 6, 2023 by avibootz
...