#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Post Help!WHy the following codes don't work in ms studio 2012


    Help! I need your help. Thanks a lot.
    I am a newbie. I am now learning pointers. So I write some some small programs.
    Code:
    #include<stdio.h>
    void main()
    {
    	int i=3,j=5;
    	int *p,*q;
    	p=&i;
    	q=&j;
    	float a=5.8,b=7.9;
    	float *c,*d;
    	c=&a;
    	d=&b;
    	char m='I',n='L';
    	char *x,*y;
    	x=&m;
    	y=&n;
    	printf("i=%d, j=%d\n",*p,*q);
    	printf("a=%g, b=%g\n",*c,*d);
    	printf("m=%c, n=%c\n",*x,*y);
    }


    The above codes runs well on VC 6.0.
    But when I changed to ms studio 2012, the program can't run.
    I see this:
    1>------ Build started: Project: test, Configuration: Debug Win32 ------
    1> max.c
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(8): error C2143: syntax error : missing ';' before 'type'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(9): error C2143: syntax error : missing ';' before 'type'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(10): error C2065: 'c' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(10): error C2065: 'a' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(10): warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(11): error C2065: 'd' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(11): error C2065: 'b' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(11): warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(12): error C2143: syntax error : missing ';' before 'type'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(13): error C2143: syntax error : missing ';' before 'type'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(14): error C2065: 'x' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(14): error C2065: 'm' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(14): warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(15): error C2065: 'y' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(15): error C2065: 'n' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(15): warning C4047: '=' : 'int' differs in levels of indirection from 'int *'
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(17): error C2065: 'c' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(17): error C2100: illegal indirection
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(17): error C2065: 'd' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(18): error C2065: 'x' : undeclared identifier
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(18): error C2100: illegal indirection
    1>c:\users\dell\documents\visual studio 2012\projects\test\test\max.c(18): error C2065: 'y' : undeclared identifier
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =
    =========


    Why?
    Last edited by aalajisi; September 5th, 2013 at 08:48 AM. Reason: something wrong with Typography
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,155
    Rep Power
    2222
    Why do you think that it doesn't work? You obviously believe that it does not work. What reasons do you have for believing that?

    Please be specific and use real-world examples.

    Also, use code tags to post code. Allowing HTML to strip out indentation makes your code unreadable. Underlining it makes it even more unreadable. Use code tags to preserve its indentation and hence its formatting.

    PS

    HINT: In case that's too subtle, answer these two questions:

    1. What is the program actually doing? For example, if it's not giving you the output you expect it to give you, then just exactly what output is it giving you? Please be specific.

    2. What do you expect it to do instead? Please be specific.

    "It doesn't work" contains no information and tells us absolutely nothing.
    Last edited by dwise1_aol; September 5th, 2013 at 12:40 AM.

IMN logo majestic logo threadwatch logo seochat tools logo