Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:52:00+00:00 2026-06-14T12:52:00+00:00

I have a very simple program to print the chars in a string but

  • 0

I have a very simple program to print the chars in a string but for some reason it is not working:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void * print_chars(char *process_string) {
    int i;
    int string_len;

    string_len = strlen(process_string);

    printf("String is %s, and its length is %d", process_string, string_len);

    for(i = 0; i < string_len; i++) {
        printf(process_string[i]);
    }

    printf("\n");
}

int main(void) {
    char *process_string;

    process_string = "This is the parent process.";

    print_chars(process_string);

    return 0;
}

When I run it in Netbeans, I get the following:

RUN FAILED (exit value 1, total time: 98ms)

If I remove the line

printf(process_string[i]);

the program runs but nothing prints out to the console (obviously).

Any ideas what I’m missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:52:02+00:00Added an answer on June 14, 2026 at 12:52 pm

    There are a couple of problems.

    One is that you’re not seeing any output from the printf("String is %s, and its length is %d", ...). This is because standard output is line buffered by default, and you are not including a newline, so it never actually decides that there’s a line ready to print. If you change the format string to add a \n, you will see the output from this command.

    The second is that you are passing a char into the first argument of printf(), where it expects a char *. This causes it to crash, as it tries to interpret that character as a pointer. You want to pass something like printf(process_string) instead. However, it’s generally a bad idea to pass a variable string directly into the first argument of printf(); instead, you should pass a format string that includes %s, and pass the string in as the corresponding argument: printf("%s\n", process_string). Or, if you want to print it character by character, printf("%c", process_string[i]), followed by a printf("\n") to flush the buffer and actually see the output. Or if you’re doing it character by character, putchar(process_string[i]) will be simpler than printf().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple print program called print.c: #include <stdio.h> int main(void){ printf(Random
I have a very simple test program, running on Solaris 5.8: #include <stdio.h> #include
I have a very simple program but this is giving me a seg fault.
I have this very simple c++ program. It's been years that I did some
I have written a very simple C program to print Hello World in my
I have a very simple C++ application. #include <stdio.h> #include <iostream> int main(int argc,
It's a very simple program. I have a function defined on the top and
I have a very simple question. I have a program that accepts an integer
I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
This one is probably very simple, but I can't seem to get it working.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.