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

  • SEARCH
  • Home
  • 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 727241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:32:43+00:00 2026-05-14T06:32:43+00:00

printf returns 1 instead of Hello World! which is the desired result. I googled

  • 0

printf returns 1 instead of “Hello World!” which is the desired result.

I googled it and think its because of the changes in the way sequences are treated.

How do I modify the code to print “Hello World!”?

http://www.mail-archive.com/python-3000@python.org/msg15119.html

import ctypes

msvcrt=ctypes.cdll.msvcrt
string=b"Hello World!"
msvcrt.printf("%s", string)
  • 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-05-14T06:32:44+00:00Added an answer on May 14, 2026 at 6:32 am

    The first argument needs to be a byte string as well:

    msvcrt.printf(b"%s", string)
    

    The return value of printf is the number of characters printed, which should be 12 in this case.

    Edit:

    If you want the string to be returned instead of printed, you can use sprintf instead. This is dangerous and NOT recommended.

    s = ctypes.create_string_buffer(100)   #must be large enough!!
    msvcrt.sprintf(s, b'%s', b'Hello World!')
    val = s.value
    

    I don’t know why you’d want to do this though, since Python has its own string formatting. sprintf is a dangerous method since it is susceptible to buffer overflows.

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

Sidebar

Related Questions

I have this function sentanceParse with a string input which returns a list. The
i have written the following code to copy a string hello world to another
I have tried something like this in my Bison file... ReturnS: RETURN expression {printf(;)}
I am using Linux and there is a custom function of which returns an
int main() { int *d=0; printf(%d\n,*d); return 0; } this works fine. >cc legal.c
int main() { double i=4; printf(%d,i); return 0; } Can anybody tell me why
#include <stdio.h> int main() { float a = 1234.5f; printf(%d\n, a); return 0; }
#include<cstdio> #include<stdlib.h> int main() { char* ptr=NULL; printf(%s,ptr); return 0; } It prints (null)
#include<stdio.h> int main() { int a,b; a=a+b; printf(%d,a); return 0; } what should be
Code #include<stdio.h> int main() { int i; printf(%d \n,'\1'); printf(%d \n,'\022'); printf(%d ,'\555'); return

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.