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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:24:43+00:00 2026-05-16T16:24:43+00:00

OK, sorry about the bad pun :P I’ve coded the old trick of HAL

  • 0

OK, sorry about the bad pun 😛

I’ve coded the old trick of HAL => IBM in C. I’ve just read the first few pages in K&R reguarding them, and I thought it would be a good first play with them.

char evil[] = "HAL";
char *ptr = evil;   
for (int i = 0; i < strlen(evil); ++i, ++ptr) {             
    (*ptr)++;           
}   
printf("%s\n", evil); // IBM

My problem is, I have two variables incrementing, i and ptr, and something is telling me one of them is redundant (perhaps I’m still not thinking C well enough).

The only reason I use i is to determine if we have read to the end of the string. Is there any way to check the pointer to see if it has arrived at the end of the string?

Update

Sorry for any confusion of the actual question. By have I missed the point I basically meant, why would I use a pointer when I needed an incrementing index to check the length as well. I could just use that index to subscript the right char from the array.

  • 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-16T16:24:43+00:00Added an answer on May 16, 2026 at 4:24 pm

    You could as well write

    for (char *ptr = evil; *ptr != '\0' ; ++ptr)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, I am sorry about the bad title, but after 5 minutes I couldn't
First, sorry about my English, I know it's bad, but I'm trying to make
First, sorry about my bad english. I came across in a very strange bug,
sorry about the funky title, I was having trouble coming up with one. First
Hi sorry about my bad terminology. Im using drupal Im using hook form alter
Bad wording on the question, sorry about that. Will try to explain what I'm
Sorry about the bad title, I couldn't think of a more descriptive one. The
Are static classes considered bad practice? I read an article about this a couple
what's wrong with my code? sorry about my bad English package sockettest; import java.io.*;
i need to send get command and take it's results. Sorry about my bad

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.