doin't compile */*/*/*------>

This is a discussion on doin't compile */*/*/*------> within the C Programming forums, part of the General Programming Boards category; help me to compile these code please Code: #include "stdio.h" #include "string.h" #define n 100 void e(int i,int *t[i],int *a[i]) ...

  1. #1
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159

    Angry doin't compile */*/*/*------>

    help me to compile these code please
    Code:
    #include "stdio.h"
    #include "string.h"
    #define n 100
    void e(int i,int *t[i],int *a[i])
    {
    *t[i]=1;
    *a[i]=1;
    
    }
    void main()
    {
    	int k=1;
        int a[n],b[n];
    	e(k,&a[k],&b[k]);
    	printf("a[k]=%i et b[k]=%i",a[k],b[k]);
    }
    errors in visual c++

    --------------------Configuration: hello - Win32 Debug--------------------
    Compiling...
    oiu.cpp
    C(4) : error C2057: expected constant expression
    C:\Program Files\Microsoft Visual Studio\MyProjects\hello\oiu.cpp(4) : error C2466: cannot allocate an array of constant size 0
    C:\Program Files\Microsoft Visual Studio\MyProjects\hello\oiu.cpp(4) : error C2057: expected constant expression
    C:\Program Files\Microsoft Visual Studio\MyProjects\hello\oiu.cpp(4) : error C2466: cannot allocate an array of constant size 0
    C:\Program Files\Microsoft Visual Studio\MyProjects\hello\oiu.cpp(6) : error C2143: syntax error : missing ';' before '->'
    C:\Program Files\Microsoft Visual Studio\MyProjects\hello\oiu.cpp(7) : error C2143: syntax error : missing ';' before '->'
    C:\Program Files\Microsoft Visual Studio\MyProjects\hello\oiu.cpp(14) : error C2664: 'e' : cannot convert parameter 2 from 'int *' to 'int *[]'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Error executing cl.exe.

    hello.exe - 7 error(s), 0 warning(s)


  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    >void e(int i,int *t[i],int *a[i])
    void e(int i, int *t[], int *a[] )

    >void main()
    Bzzt. Wrong. int main( )

    >e(k,&a[k],&b[k])
    e(k,&a,&b)

    >printf("a[k]=%i et b[k]=%i",a[k],b[k]);
    printf("a[k]=%d et b[k]=%d",a[k],b[k]);
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    why has it become popular to do this
    Code:
    #include "stdio.h"
    #include "string.h"
    It should be
    Code:
    #include <stdio.h>
    #include <string.h>
    There is a difference, one looks in the current directory or one specified by command line args to the compiler before looking in the system include directories! So you could have a version of stdio.h in the current directory and it could be different than the one in /usr/include!
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    > why has it become popular to do this
    It's just one of many persistent mistakes in enjoy's code.
    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.

  5. #5
    C Programmer Stack Overflow's Avatar
    Join Date
    Apr 2004
    Posts
    477

    Post

    Does this compile?

    Code:
    #include <stdio.h>
    #include <string.h>
    
    void e(int i,int *t,int *a) {
    	*t = 1;
    	*a = 1;
    }
    
    int main() {
    	int k = 1;
        int a[100], b[100];
    
    	e(k, &a[k], &b[k]);
    	printf("a[k]=%i et b[k]=%i", a[k], b[k]);
    
    	return 0;
    }
    Fix #1: *a[i] amd void e(int i,int *t,int *a)

    Fix #2: *t[i]=1; and *a[i]=1 are not needed because you already defined your array calling the function so it can be changed to: *t = 1; and *a = 1;

    Fix #3: int a[n]; will not work, it needs a number instead of a variable constant so instead of that use int a[100];

    Fix #4: Use int main() instead, void main() isn't to recommended by programmers.


    Hope this helps,
    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  6. #6
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    For the printf statement, you need %d instead of %i. His array declaration was valid because he #defines n at the top of his code.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  7. #7
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    thanks all my code is compilling now ........ (:d

  8. #8
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    %d and %i are interchangable in printf you should know that XSquared.

  9. #9
    /*enjoy*/
    Join Date
    Apr 2004
    Posts
    159
    i approve these linuxdude

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Quote Originally Posted by linuxdude
    %d and %i are interchangable in printf you should know that XSquared.
    I should, but I didn't. Until now. Thanks.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  11. #11
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by enjoy
    i approve these linuxdude
    Is this like those Presidential ads they keep running?

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small -> big -> bigger -> bigger than bigger -> ?
    By happyclown in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-11-2009, 01:12 PM
  2. Replies: 2
    Last Post: 09-20-2006, 06:40 PM
  3. Dev-C++ -> Tools - > Editor -> Syntax
    By Yuri2 in forum C++ Programming
    Replies: 19
    Last Post: 07-03-2006, 08:48 AM
  4. > > > Urgent Help < < <
    By CodeCypher in forum C Programming
    Replies: 2
    Last Post: 01-31-2006, 02:06 PM

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