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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:11:29+00:00 2026-06-08T23:11:29+00:00

I have been researching like mad while I learning C. I have been debugging

  • 0

I have been researching like mad while I learning C. I have been debugging a C program and I thought I had some major issues here. Now I have critical issues. I made a dummy program to print two strings in one statement as follows:

   #include<stdio.h>

int main(int argc, char* argv[])
{
    char *herp = "Derp";
    char *derp = "Herp";

    printf("Herp %s Derp %s\n", herp, derp);

    return 0;
}

This prints out as expected. I get

Herp Derp Derp Herp

So, I thought, let me debug my own program by doing something similar. The following line in my program

printf("word is: %s and jumbled word is: %s\n", word, jumbleWord);

Should print out something like

Word is: word and jumbled word is: dowr

But it prints out something like

and jumbled word is: dowr

Where did the first part of the output go? I need to be able to print these both on the same line to debug. Also, the fact that a statement like this is not working tells me that really weird things are going on and I am bald from tearing my hair out. As my linked posts indicates, I would eventually like to compare these string values, but how can I even do that if printf() is not working right?

I am posting the entire program below so you can see where everything is happening. I am just learning how to use pointers. I originally had two pointers point at the same memory when I wanted to jumble a word and that didn’t work very well! So I fixed that and got two separate memory spaces with the words I need. Now, I just can’t print them. This all makes sense given the code below:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX_WORD_LENGTH 25

//Define global variables 
int numWords; 

//Preprocessed Functions 
void jumblegame();
void readFile(char *[]);
void jumbleWord(char *);
void guess(char *,char *); 

int main(int argc, char* argv[])
{
    jumblegame();
    return 0;
}

void jumblegame()
{
    //Load File 
        int x = 5050; //Rows
        char *words[x];
        readFile(words);

    //Define score variables 
        int totalScore = 0;
        int currentScore = 0; 

   //Repeatedly pick a random work, randomly jumble it, and let the user guess what it is
         srand((unsigned int)time(NULL));
         int randomNum = rand() % numWords + 1;

         char source[MAX_WORD_LENGTH + 1];
         char jumble[MAX_WORD_LENGTH + 1];

         strncpy(source, words[randomNum], MAX_WORD_LENGTH + 1);
         strncpy(jumble, words[randomNum],MAX_WORD_LENGTH + 1);

         jumbleWord(jumble);

         guess(source, jumble);
         //printf("Random word is: %s\n ", words[randomNum]);
         //randomly jumble it           
}

void readFile(char *array[5049]) 
{
    char line[256]; //This is to to grab each string in the file and put it in a line. 
    int z = 0; //Indice for the array

    FILE *file;
    file = fopen("words.txt","r");

    //Check to make sure file can open 
    if(file == NULL)
    {
        printf("Error: File does not open.");
        exit(1);
    }
    //Otherwise, read file into array  
    else
    {
        while(!feof(file))//The file will loop until end of file
        {
           if((fgets(line,256,file))!= NULL)//If the line isn't empty
           {
             int len = strlen(line); 
             if (len > 0 && line[len - 1] == '\n') line[len - 1] = '\0';
             array[z] = malloc(strlen(line) + 1);
             strcpy(array[z],line);
             z++;
           }    
        }
    }
    fclose(file);
    numWords = z; 
}

void jumbleWord(char *word)
{
    int wordSize = strlen(word) - 1; 
    //durstenfeld Implementation of Fischer-Yates Shuffle
        int i; 
        int j; 
        char temp;
        for(i = wordSize - 1; i > 0; i--)
        {
            j =  rand() % (i + 1);
            temp = word[j];
            word[j] = word[i];
            word[i] = temp;
        }
}

void guess(char *word, char *jumbleWord)
{
     printf("original word is: %s\n", word);
     printf("jumbled word is: %s\n", jumbleWord);
     printf("source is: %s and jumbled word is: %s\n", word, jumbleWord);
}

I think most people at this point would burn C and slap themselves for sucking so bad at it. However, I am going to keep trucking along. So let me apologize for any derp, but please know that I have spent many hours probably being really stupid and staring at this. I would love to say, “Hey, C is so stupid because it won’t do what I am telling it to“. Unfortunately, I can’t believe this. I think it is doing exactly what I am telling it to do, but I am too close to this problem to see what I am doing wrong.

As always, thank you for your help. My deepest respect,
GeekyOmega

  • 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-08T23:11:31+00:00Added an answer on June 8, 2026 at 11:11 pm

    You have a carriage return '\r' at the end of the word(s).

    Carriage returns move the write cursor to the left of the screen, so it is writing it, but it’s overwriting what was already there.

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

Sidebar

Related Questions

I have been researching options for printing report-like data via a web application. Some
I have been researching OpenGL programming on Mac OS X. While a fair amount
I have been researching this for a while but got no convinced answer. From
I have a problem I have been researching for a while on the internet
I need to cluster some text documents and have been researching various options. It
I have been researching asynchronous messaging, and I like the way it elegantly deals
I have been researching this problem for a while now and I just can't
I have been researching and writing/re-writing a program to do this task for a
I have been researching for a while and have actually created a prototype ASP.NET
I have a database design problem which I have been researching for a while

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.