rnty's Profile User Rating: -----

Reputation: 19 Tradesman
Group:
Active Members
Active Posts:
187 (0.14 per day)
Joined:
14-August 12
Profile Views:
15,764
Last Active:
User is offline Feb 11 2016 03:28 PM
Currently:
Offline

Previous Fields

Country:
IN
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
AMD
Favorite Gaming Platform:
Classic
Your Car:
Who Cares
Dream Kudos:
0

Latest Visitors

Icon   rnty UnKnowledgeable and UnHappy but UnFazed and UnMoved

Posts I've Made

  1. In Topic: Copying from file to string in C

    Posted 7 Feb 2016

    Is this a good solution?

    #include <stdio.h>
    #include <stdlib.h>
    
    #define PRECINCT 5
    #define MAX_FILE_SIZE 1000
    
    int main(){
    
        FILE* fp;
        char buffer[MAX_FILE_SIZE];
        int A[PRECINCT],B[PRECINCT],C[PRECINCT],D[PRECINCT];
        int loop_var;
    
        fp=fopen("Results.txt","r");
    
        if(fp==NULL){
            printf("Error opening file");
            exit(1);
        }
    
        //printf("File opened");
        for(loop_var=0; loop_var<MAX_FILE_SIZE; loop_var++)
        {
            int c= fgetc(fp);
    
            if (c==EOF)
            {
                buffer[loop_var]='\0';
                break;
            }
            buffer[loop_var]= c;
        }
    
        puts(buffer);
    
        fclose(fp);
    
        return 0;
    }
    
    
    
  2. In Topic: Garbage characters printed in between

    Posted 26 Jan 2016

    Thank you very much
  3. In Topic: Research areas in Programming Languages

    Posted 15 Dec 2015

    View Postmodi123_1, on 15 December 2015 - 07:39 PM, said:

    Quote

    I would like to take up some area of programming languages as my research area

    Isn't that your area to research based on your own interests and not some internet whim?

    I mean basic search terms like "current areas of computer research" yield 919,000,000 some odd results.


    I already know a few like visual programming languages and code optimization. I was hoping to get a few things that I don't know about or rather a consolidated list, then download papers on each topic, read and then finally decide. I am sure about PL but what inside PL is the question. To answer that I must know what what inside PL. :)
  4. In Topic: Attacking queen problem

    Posted 11 Dec 2015

    This is what I understood from your post. I hope my code has no bugs now.
    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int chess_board[8][8]={{}};
        int queen1r,queen1c,queen2r,queen2c;
    
        printf("\nATTACKING QUEENS\n");
    
        printf("Enter the position of the first queen\n");
        scanf("%d %d",&queen1r,&queen1c);
    
        chess_board[queen1r][queen1c]=1;
    
        //while(queen1c >= 0 && queen1r >= 0)
        for(;queen1c >= 0 && queen1r >= 0; queen1r--,queen1c--)
            chess_board[queen1r][queen1c]=1;
    
        //while(queen1c <= 8 && queen1r <= 8)
        for(;queen1c <=8 && queen1r <=8; queen1r++,queen1c++)
            chess_board[queen1r][queen1c]=1;
    
        //while(queen1c >= 0 && queen1r <= 8)
        for(;queen1c >= 0 && queen1r <=8; queen1r++,queen1c--)
            chess_board[queen1r][queen1c]=1;
    
        //while(queen1c <= 8 && queen1r >= 0)
        for(;queen1c <= 8 && queen1r >= 0; queen1r--,queen1c++)
            chess_board[queen1r][queen1c]=1;
    
        printf("Enter the position of the second queen\n");
        scanf("%d %d",&queen2r,&queen2c);
    
        if(chess_board[queen2r][queen2c]==1)
            printf("The queens are attacking");
    
        else if(queen1r==queen2r || queen1c==queen2c)
            printf("The queens are attacking");
    
        else
            printf("The queens are not attacking");
    
        return 0;
    }
    
    
    


    Thanks a ton for explaining the logic. If the code is correct now, can you give some optimization ideas.
  5. In Topic: Attacking queen problem

    Posted 11 Dec 2015

    Is this ok?

    #include <stdio.h>
    #include <stdlib.h>
    
    int main()
    {
        int chess_board[8][8]={{}};
        int queen1r,queen1c,queen2r,queen2c;
    
        printf("\nATTACKING QUEENS\n");
    
        printf("Enter the position of the first queen\n");
        scanf("%d %d",&queen1r,&queen1c);
    
        chess_board[queen1r][queen1c]=1;
    
        while(queen1c >= 0 && queen1r >= 0)
            chess_board[--queen1r][--queen1c]=1;
    
        while(queen1c <= 3 && queen1r <= 3)
            chess_board[++queen1r][++queen1c]=1;
    
        while(queen1c >= 0 && queen1r <= 3)
            chess_board[++queen1r][--queen1c]=1;
    
        while(queen1c <= 3 && queen1r >= 0)
            chess_board[--queen1r][++queen1c]=1;
    
        printf("Enter the position of the second queen\n");
        scanf("%d %d",&queen2r,&queen2c);
    
        if(chess_board[queen2r][queen2c]==1)
            printf("The queens are attacking");
    
        else if(queen1r==queen2r || queen1c==queen2c)
            printf("The queens are attacking");
    
        else
            printf("The queens are not attacking");
    
        return 0;
    }
    
    
    


    EDIT: I mean like are there any corner cases that I missed?

Comments

rnty has no profile comments yet. Why not say hello?