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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:56:46+00:00 2026-06-17T17:56:46+00:00

void convert(char *str){ int i = 0; while (str[i]){ if (isupper(str[i])){ tolower(str[i]); } else

  • 0
void convert(char *str){
  int i = 0;
  while (str[i]){
    if (isupper(str[i])){
      tolower(str[i]);
    }
    else if (islower(str[i])){
      toupper(str[i]);
    }
    i++;
  }
  printf(str);
}

In the function, I tried to reverse the case of each of the letters in a string. I called the function like this:

convert(input);

Where input is a type of char *. I got a segmentation fault error. What’s wrong here?

Thank you!

UPDATE:
My input is taken from argv[1].

  char *input;
  if (argc !=2){/* argc should be 2 for correct execution */
    /* We print argv[0] assuming it is the program name */
    printf("Please provide the string for conversion \n");
    exit(-1);
  }
  input = argv[1];
  • 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-17T17:56:47+00:00Added an answer on June 17, 2026 at 5:56 pm

    The reason this does not work is that you are dropping the results of toupper and tolower. You need to assign the results back to the string passed into your function:

    if (isupper(str[i])){
        str[i] = tolower(str[i]);
    } else if (islower(str[i])){
        str[i] = toupper(str[i]);
    }
    

    Note that in order for this to work the str must be modifiable, meaning that a call convert("Hello, World!") would be undefined behavior.

    char str[] = "Hello, World!";
    convert(str);
    printf("%s\n", str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code!(sorry for my poor english) #include<stdio.h> int convert(char ch); int main(void)
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
I want to convert the NSString* str to char* ch , for using it
#include <stdio.h> #include <ctype.h> int isPalindrome( char *str, int length ) { if (
this is my example code: #include<stdio.h> #include<string.h> #include<ctype.h> void convert(char *a, char *b) {
I am trying to convert a void pointer to an array of classes in
Each time I use Merge() I have the following: 'Cannot implicitly convert type 'void'
static void Main(string[] args) { //read in the file StreamReader convert = new StreamReader(../../convert.txt);
Is it possible to convert this java code snippet to php? public void testBalanceReturnsToZeroOnVending()
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]

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.