Array assigning error

This is a discussion on Array assigning error within the C Programming forums, part of the General Programming Boards category; Hi, while running the below mentioned code i got a error can any one help to fix these error. The ...

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    2

    Lightbulb Array assigning error

    Hi,

    while running the below mentioned code i got a error can any one help to fix these error.
    The error message is"cannot convert 'int (*)(s) to int*' in function main() " and "'p' is assigned a value that never used in function main()"

    Code:
    #include<stdio.h>
    #include<conio.h>
    main()
    {
      int s[4][2] = {
        {123, 33},
        {124, 35},
        {125, 36},
        {126, 37}
      };
      int (*p)[2];
      int i, j, *pint;
      for (i = 0; i <= 3; i++) {
        p = &s[i];
        pint = p;
        printf("\n");
        for (j = 0; j < 1; j++)
          printf("%d", *(pint + j));
      }
      getch();
      clrscr();
    }
    Last edited by Salem; 06-28-2012 at 01:04 AM. Reason: demunging useless colour

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,445
    What are you trying to do?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    Try
    pint = p[0];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Which one do you want?
    Code:
    int (*p)[2];    // pointer `p` to array of 2 int's
    int *p[2];      // array `p` of 2 pointers to int
    Disclaimer: This post shows my ignorance at the time of its making. I claim ownership of but not responsibility for all errors in it. Reference at your own peril.

  5. #5
    Registered User
    Join Date
    Jun 2012
    Posts
    2
    thanks dude its work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bus error when assigning value to member of struct
    By popapez in forum C Programming
    Replies: 4
    Last Post: 09-23-2009, 08:37 PM
  2. error in assigning a path ?
    By GSalah in forum C++ Programming
    Replies: 18
    Last Post: 11-17-2006, 03:48 PM
  3. Assigning the value of a const array to a normal array
    By Accident Prone in forum C++ Programming
    Replies: 6
    Last Post: 08-11-2003, 10:40 PM
  4. Error with assigning ..interrupt value?
    By jawwadalam in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-15-2003, 10:28 AM
  5. Assigning std::strings result in error
    By NixPhoeni in forum C++ Programming
    Replies: 4
    Last Post: 12-07-2001, 03:01 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21