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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:54:12+00:00 2026-06-07T07:54:12+00:00

this code works completely fine in my pc while i compile it with codeblocks

  • 0

this code works completely fine in my pc while i compile it with codeblocks 10.05. the code doesn’t give an error or warning whatsoever! But while submitting it to an online judge community of coding they reply me with an compilation error!
Here is my code:

#include<stdio.h>
#include<stdlib.h>
int main()
{
    int j=1;
    while(j=1){
        int x,y,i,j,num,count=0,p,k;
        for(;;){
            printf("enter two integers. they must not be equal and must be between 1 and 100000\n");
            scanf("%d%d",&i,&j);
            if(i>=1 && i<100000 && j>=1 && j<100000 && i!=j){
                break;
            }
            else{
                printf("try the whole process again\n");
            }
        }
        if(i>j){
            x=i;
            y=j;
        }
        else{
            x=j;
            y=i;
        }//making x always greater than y
        int *cyclelength=(int *)malloc(5000*sizeof(int));
        if (NULL==cyclelength){
            printf("process aborted");
            return 0;
        }
        else{
            /*solution part for the range of number. and solution for each number  put into cyclelength.*/
            num=y;
            while(num<=x){
                p=1;
                k=num;
                while(k!=1){
                    if(k%2==0)
                        k=k/2;
                    else
                        k=3*k+1;
                    p+=1;
                    }
                cyclelength[count]=p;
                num+=1;
                count+=1;
            }
            int c=0;
            int max=cyclelength[c];
            for(c=0;c<x-y-1;c+=1){
                if(max<cyclelength[c+1]){
                    max=cyclelength[c+1];
                }
            }
            free(cyclelength);
            cyclelength = NULL;
            printf("%d,%d,%d\n",i,j,max);
        }
    }
}

and when i try to submit it in an online community under ANSI C 4.1.2 – GNU C Compiler with options: -lm -lcrypt -O2 -pipe -ansi -DONLINE_JUDGE this format. they send me a compilation error message!

Our compiler was not able to properly proccess your submitted code. This is the error returned:
code.c: In function 'main':
code.c:25:10: error: expected expression before '/' token
code.c:27:19: error: 'cyclelength' undeclared (first use in this function)
code.c:27:19: note: each undeclared identifier is reported only once for each function it appears in
code.c:10:18: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result

why am i getting this?? where is my fault?? Is the coding format not matching?? I am a beginner!

  • 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-07T07:54:15+00:00Added an answer on June 7, 2026 at 7:54 am

    with the -ansi option the errors are ANSI compliance failures:

    }//making x always greater than y
    

    should be

    } /* making x always greater than y */
    

    In the line 26; you can’t declare cyclelength here; it needs to be at the top of the function (at line 5)

    int main()
    {
        int *cyclelength;
    ...
        cyclelength=(int *)malloc(5000*sizeof(int));
    

    The scanf problem is a warning because not checking the return value of scanf assumes that it has succeeded; so you should do something like:

    do {
        printf("enter two integers. they must not be equal and must be between 1 and 100000\n");
        number_read = scanf("%d%d", &i, &j);
        if (number_read < 0) /* read failed, e.g. user entered ctrl-d */
            return 0;
        } while (number_read != 2);
    

    of course you’ll need to declare number_read at the top of the function

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

Sidebar

Related Questions

This code works fine, but I'll want to handle exception if any thing goes
This code works fine in Chrome. However, in Firefox, when it hits the GMxhr
This code works well for displaying separate xml items in my main.xml. But is
this code works fine until I start scrolling: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
This code works well: UIDatePicker *pickerView = [[UIDatePicker alloc] initWithFrame:pickerFrame]; [pickerView addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged];
This code works for me except it only checks for a duplicate once, and
This code works: monkey.h @interface monkey : NSObject { NSNumber *monkeyRanch; } @property (nonatomic,
This code works (when ControlType=dropDown then the background yellow ): <Window x:Class=TestCollapsed.Views.MainView xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
This code works: class Test { public: Test(string name) : _name(name) {}; bool operator()()
This code works perfectly in Ubuntu, Windows, and Mac OS X. It also works

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.