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 8544345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:32:05+00:00 2026-06-11T12:32:05+00:00

In my my program, I am simply reading wind direction from a sensor. I

  • 0

In my my program, I am simply reading wind direction from a sensor. I am having trouble printing out the English version of the direction. The basic algorithm is this:

(values are in degrees, read from a struct)

string direction;  (I know you have to create a char array, just not sure how)

if(sensor.windir > 11 && sensor.windspeed < 34)
 {
 direction = "NNE";
 }

  if(sensor.windir > 34 && sensor.windspeed < 57)
 {
 direction = "NE";
 }



  .....


 printf(" Current windir is %s\n", direction);

I’m rusty on C and need a refresher on how to print the wind direction string based on its value range defined in the “if” statements. I will not need more than 3 chars in my 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-06-11T12:32:06+00:00Added an answer on June 11, 2026 at 12:32 pm

    For your problem at hand, the following will do:

    char const * s = "[error]";
    
    if (speed => 1 && speed < 13)       { s = "NW"; }
    else if (speed >= 13 && speed < 27) { s = "NE"; }
    else if (speed >= 27 && speed < 39) { s = "NS"; }
    
    printf("The direction is %s.\n", s);
    

    This only works for compile-time constant string literals.

    If you need to create dynamic strings, you need to create a char array (like char buf[1024];) and use something like snprintf to populate it with a string.

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

Sidebar

Related Questions

I'm writing a program that simply demonstrates writing and reading from a bounded buffer
I'm learning java and I have made simple program that simply reads value from
I'm having a problem reading and processing data from my server. I've spent hours
I have a simple RabbitMQ test program randomly enqueuing messages, and another reading them,
I'm writing a small program to record reading progress, the data models are simple:
At a unix command line, what's the difference between executing a program by simply
In C#, is there a way to make a program that simply eats roughly
I need to build a content gathering program that will simply read numbers on
So all I simply want to do is make a Ruby program that reads
I've been reading a bit about immutable structures such as string. Simply put, they

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.