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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:34:14+00:00 2026-06-11T13:34:14+00:00

In C, I want to check a given array of chars for an arbitrary

  • 0

In C, I want to check a given array of chars for an arbitrary letter, and change it according to what it is. For example, the characters “a” or “A” would be changed to “4”(the character representing 4). This is a coding excercise for me 🙂

The code is as follows:

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <zlib.h>

#define NUM_BUFFERS 8
#define BUFFER_LENGTH 1024

char buffArrays[NUM_BUFFERS][BUFFER_LENGTH];

int main(int argc, const char* arg[v])
{
    const char a[] = "a";

    gzFile file;
    file = gzopen("a.txt", "rb"); //contains 8 lines of 1024 'a's
    int counter = 0;
    while(counter < NUM_BUFFERS)
    {
        gzread(file, buffArrays[counter], BUFFER_LENGTH - 1);
        counter++;
    }
    counter = 0;
    while(counter < NUM_BUFFERS)
    {
        int i = 0;
        for( i; i < BUFFER_LENGTH; i++ )
        {
            int *changed = &buffArrays[counter][i];
            if( memcmp(&a, changed, 1) == 0 )
                printf("SUCCESS\n");
        }
        counter++;
    }
    gzclose(file);
    return 0;
}

This code never reaches the “SUCCESS” part. This says to me that either

(1) the value of changed is not pointing to the correct thing
(2) the pointer &a is incorrect
(3) I am completely wrong and it is something else

Any help would be appreciated.

  • 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-11T13:34:15+00:00Added an answer on June 11, 2026 at 1:34 pm

    Two things.

    The following assigns the value 0x61 or 'a' to the character string.

    const char a[] = 'a';
    

    You probably rather meant to write

    const char a = 'a'; /* assign a character to a character */
    

    or

    const char a[] = "a"; /* assign a string to a string */
    

    The next thing is with the following statement. Hereby you assign a pointer to an int with the memory address of a char. Which invokes undefined behavior as you are reading over the bounds of your valid memory in the next statement.

    int *changed = &bufferArrays[counter][i]; 
    

    Hereby you compare the first four bytes starting from both addresses. Both variables are only one byte wide.

    if( memcmp(&a, changed, 4) == 0 )
    

    If you only want to know whether there is an ‘a’ in some of your buffer, why don’t you just.

    int i, j;
    for (i = 0; i < NUM_BUFFERS; i++)
      for (j = 0; j < BUFFER_LENGTH; j++)
        if (bufferArrays[i][j] == 'a') printf("got it!\n");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given an array @A we want to check if the element $B is in
I want to check whether a given file exists in android sd card. I
I want to implement a check function that given two strings s1 and s2
I want to check value in array if exits then show Exits otherwise show
Is there any way to check if a given index of an array exists?
Given an array of values, I want to determine if its an increasing or
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is
I want to check if my many column in datagridview is empty. here my

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.