Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error C2440

error C2440

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structurestutorial
19 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M MsmVc

    I all I got one example from planetsourcecode.When i compile these code then i am geeting error please help me.

    #include "stdafx.h"
    #include<stdlib.h>
    #include<stdio.h>
    #include<conio.h>
    #include<string.h>

    int _tmain(int argc, _TCHAR* argv[])
    {
    char *s;
    int i,l,*a,f,c,x;
    printf("Enter a string : ");
    scanf("%s",s);
    l=strlen(s);
    s[l]=0;
    a=(char*)malloc(l);
    for(i=0;i=l)

            {
            a\[x\]=c=0;
            if(x<0){f=0;break;}
            a\[x\]++;
        }
    }
    
    printf("Completed");
    
    return 0;
    

    }

    Error

    error C2440: '=' : cannot convert from 'char *' to 'int *'
    error C2109: subscript requires array or pointer type
    error C2143: syntax error : missing ';' before ')'

    Please help me

    A Offline
    A Offline
    Adam Roderick J
    wrote on last edited by
    #2

    You can seee the error... Now decide why?

    int i,l,*a,f,c,x;
    printf("Enter a string : ");
    scanf("%s",s);
    l=strlen(s);
    s[l]=0;
    a=(char*)malloc(l);

    Величие не Бога может быть недооценена.

    M 1 Reply Last reply
    0
    • A Adam Roderick J

      You can seee the error... Now decide why?

      int i,l,*a,f,c,x;
      printf("Enter a string : ");
      scanf("%s",s);
      l=strlen(s);
      s[l]=0;
      a=(char*)malloc(l);

      Величие не Бога может быть недооценена.

      M Offline
      M Offline
      MsmVc
      wrote on last edited by
      #3

      yes i know there is error.When i change Int *a to CHAR *a.But still i have two error. Error

      error C2109: subscript requires array or pointer type
      error C2143: syntax error : missing ';' before ')'

      If you know solution or condition then please help me

      A 1 Reply Last reply
      0
      • M MsmVc

        yes i know there is error.When i change Int *a to CHAR *a.But still i have two error. Error

        error C2109: subscript requires array or pointer type
        error C2143: syntax error : missing ';' before ')'

        If you know solution or condition then please help me

        A Offline
        A Offline
        Adam Roderick J
        wrote on last edited by
        #4

        I cannot get the this code? Surely having problem, but whether it is related to your code or formating error, please check these things, you can solve these issues. These are just syntax errors.

        for(i=0;i f=1,c=0;

        Величие не Бога может быть недооценена.

        M 1 Reply Last reply
        0
        • A Adam Roderick J

          I cannot get the this code? Surely having problem, but whether it is related to your code or formating error, please check these things, you can solve these issues. These are just syntax errors.

          for(i=0;i f=1,c=0;

          Величие не Бога может быть недооценена.

          M Offline
          M Offline
          MsmVc
          wrote on last edited by
          #5

          Thanks for reply I have change in code then runing well.Please check it.

          #include "stdafx.h"
          #include<stdlib.h>
          #include<stdio.h>
          #include<conio.h>
          #include<string.h>

          int _tmain(int argc, _TCHAR* argv[])
          {
          char *s,*a;
          int i,l,f,c,x;
          printf("Enter a string : ");
          scanf("%s",s);
          l=strlen(s);
          s[l]=0;
          a=(char*)malloc(l);
          for(i=0;i<l;i++);
          f=1,c=0;
          while(f)

              {
              x=l-1;
              a\[x\]=c++;
              for(i=0;i<l && c-1<l;i++)
              printf("%c",s\[a\[x\]\]);
              if(i>=l) 
              printf("\\n");
              while(a\[x\]>=l)
          
          
                  {
                  a\[x\]=c=0;
                  if(x<0){f=0;break;}
                  a\[x\]++;
              }
          }
          
          printf("Completed");
          
          return 0;
          

          }

          Error

          Run-Time Check Failure #3 - The variable 's' is being used without being initialized.

          Please help me

          A 1 Reply Last reply
          0
          • M MsmVc

            Thanks for reply I have change in code then runing well.Please check it.

            #include "stdafx.h"
            #include<stdlib.h>
            #include<stdio.h>
            #include<conio.h>
            #include<string.h>

            int _tmain(int argc, _TCHAR* argv[])
            {
            char *s,*a;
            int i,l,f,c,x;
            printf("Enter a string : ");
            scanf("%s",s);
            l=strlen(s);
            s[l]=0;
            a=(char*)malloc(l);
            for(i=0;i<l;i++);
            f=1,c=0;
            while(f)

                {
                x=l-1;
                a\[x\]=c++;
                for(i=0;i<l && c-1<l;i++)
                printf("%c",s\[a\[x\]\]);
                if(i>=l) 
                printf("\\n");
                while(a\[x\]>=l)
            
            
                    {
                    a\[x\]=c=0;
                    if(x<0){f=0;break;}
                    a\[x\]++;
                }
            }
            
            printf("Completed");
            
            return 0;
            

            }

            Error

            Run-Time Check Failure #3 - The variable 's' is being used without being initialized.

            Please help me

            A Offline
            A Offline
            Adam Roderick J
            wrote on last edited by
            #6

            Here, i think you have to help yourself, by learning the syntax of C. I prefer you to read a C programming book to get throught with syntax.:thumbsup: See in your code, you cannot use scanf as you wish, it is expecting the address of s. so your compiler is complaining

            scanf("%s",s);

            Expected code is

            scanf("%s",&s);

            Величие не Бога может быть недооценена.

            M 1 Reply Last reply
            0
            • A Adam Roderick J

              Here, i think you have to help yourself, by learning the syntax of C. I prefer you to read a C programming book to get throught with syntax.:thumbsup: See in your code, you cannot use scanf as you wish, it is expecting the address of s. so your compiler is complaining

              scanf("%s",s);

              Expected code is

              scanf("%s",&s);

              Величие не Бога может быть недооценена.

              M Offline
              M Offline
              MsmVc
              wrote on last edited by
              #7

              Thanks for reply Now i am getting exception in line s[l]=0;

              Unhandled exception at 0x1026f8bc (msvcr90d.dll) in TestingProject.exe: 0xC0000005: Access violation reading location 0xcc006975.

              G 1 Reply Last reply
              0
              • M MsmVc

                Thanks for reply Now i am getting exception in line s[l]=0;

                Unhandled exception at 0x1026f8bc (msvcr90d.dll) in TestingProject.exe: 0xC0000005: Access violation reading location 0xcc006975.

                G Offline
                G Offline
                Game point
                wrote on last edited by
                #8

                try this

                char *s = new char;

                :~ Failure is Success If we learn from it!!:~

                M 1 Reply Last reply
                0
                • G Game point

                  try this

                  char *s = new char;

                  :~ Failure is Success If we learn from it!!:~

                  M Offline
                  M Offline
                  MsmVc
                  wrote on last edited by
                  #9

                  I have change in code char *s = new char(230) Still i have same exception. Please help me

                  E 1 Reply Last reply
                  0
                  • M MsmVc

                    I all I got one example from planetsourcecode.When i compile these code then i am geeting error please help me.

                    #include "stdafx.h"
                    #include<stdlib.h>
                    #include<stdio.h>
                    #include<conio.h>
                    #include<string.h>

                    int _tmain(int argc, _TCHAR* argv[])
                    {
                    char *s;
                    int i,l,*a,f,c,x;
                    printf("Enter a string : ");
                    scanf("%s",s);
                    l=strlen(s);
                    s[l]=0;
                    a=(char*)malloc(l);
                    for(i=0;i=l)

                            {
                            a\[x\]=c=0;
                            if(x<0){f=0;break;}
                            a\[x\]++;
                        }
                    }
                    
                    printf("Completed");
                    
                    return 0;
                    

                    }

                    Error

                    error C2440: '=' : cannot convert from 'char *' to 'int *'
                    error C2109: subscript requires array or pointer type
                    error C2143: syntax error : missing ';' before ')'

                    Please help me

                    F Offline
                    F Offline
                    Fareed Rizkalla
                    wrote on last edited by
                    #10

                    You can use casting, I know it's available in C++. Don't know about C, does it have to be C or C++?

                    M 1 Reply Last reply
                    0
                    • F Fareed Rizkalla

                      You can use casting, I know it's available in C++. Don't know about C, does it have to be C or C++?

                      M Offline
                      M Offline
                      MsmVc
                      wrote on last edited by
                      #11

                      thank for make comment but sorry can you describe in detail.What's not available? please describe in detail.

                      F 1 Reply Last reply
                      0
                      • M MsmVc

                        thank for make comment but sorry can you describe in detail.What's not available? please describe in detail.

                        F Offline
                        F Offline
                        Fareed Rizkalla
                        wrote on last edited by
                        #12

                        i'm not sure if you've attempted to add float to an int data type, but you get compiler errors in the end. you want to add float and int to each other. Casting: int x = 12; float y = 4.0; int sum = x + (int)y;

                        M 1 Reply Last reply
                        0
                        • F Fareed Rizkalla

                          i'm not sure if you've attempted to add float to an int data type, but you get compiler errors in the end. you want to add float and int to each other. Casting: int x = 12; float y = 4.0; int sum = x + (int)y;

                          M Offline
                          M Offline
                          MsmVc
                          wrote on last edited by
                          #13

                          Thank for reply but it's not useful for me because where i use int + float.If you have solution then please help me.

                          1 Reply Last reply
                          0
                          • M MsmVc

                            I have change in code char *s = new char(230) Still i have same exception. Please help me

                            E Offline
                            E Offline
                            Emilio Garavaglia
                            wrote on last edited by
                            #14

                            no, no, no .... That's not the way to go! You put some code with some syntax error and even some misconception in it. That reveal that you are not understanding what your code has to do. The compiler just gives some errors, but those errors are random as your code is. Attempting to fix those errors doesn't lead anywhere: you're never granted your code will do what you expect. For example:

                            char \*s;
                            int i,l,\*a,f,c,x;
                            printf("Enter a string : ");
                            scanf("%s",s);
                            

                            s is a pointer pointing to nowhere: where do ypu thoing your scanf can write to ?!? s[l]=0; tries to write to nowhere since s is nowhere a is a pointer to int, but you do a=(char*)malloc(l): what did you want to do? allocating char-s or int-s ?!

                            for(i=0;i
                            f=1,c=0;
                            while(f)

                            This is a mess of tokens with no syntax meaning! Raed about the for syntax, and understand the proper use of '()', ',', and ';'. x=l-1 Wow... you're looking for problems: never use names like "O" and "l": I have to change font before find it's "l-1" and not "l-l" ... Do you get what I mean? If not, than that demonstrate the problem :-) Then: I see a malloc, but i don't see a free: not a good way to program... I don't continue, but what can you do if you don't have clear in your mind what you're gonna do?

                            2 bugs found. > recompile ... 65534 bugs found. :doh:

                            M 1 Reply Last reply
                            0
                            • E Emilio Garavaglia

                              no, no, no .... That's not the way to go! You put some code with some syntax error and even some misconception in it. That reveal that you are not understanding what your code has to do. The compiler just gives some errors, but those errors are random as your code is. Attempting to fix those errors doesn't lead anywhere: you're never granted your code will do what you expect. For example:

                              char \*s;
                              int i,l,\*a,f,c,x;
                              printf("Enter a string : ");
                              scanf("%s",s);
                              

                              s is a pointer pointing to nowhere: where do ypu thoing your scanf can write to ?!? s[l]=0; tries to write to nowhere since s is nowhere a is a pointer to int, but you do a=(char*)malloc(l): what did you want to do? allocating char-s or int-s ?!

                              for(i=0;i
                              f=1,c=0;
                              while(f)

                              This is a mess of tokens with no syntax meaning! Raed about the for syntax, and understand the proper use of '()', ',', and ';'. x=l-1 Wow... you're looking for problems: never use names like "O" and "l": I have to change font before find it's "l-1" and not "l-l" ... Do you get what I mean? If not, than that demonstrate the problem :-) Then: I see a malloc, but i don't see a free: not a good way to program... I don't continue, but what can you do if you don't have clear in your mind what you're gonna do?

                              2 bugs found. > recompile ... 65534 bugs found. :doh:

                              M Offline
                              M Offline
                              MsmVc
                              wrote on last edited by
                              #15

                              Thanks for vital information and suggestion. I want to generate Combination of given String.Like this CString test="ABC", then generate like this AB AC AA BB BC BA CC CA CB If you have any type solution or suggestion then please help me.

                              E 1 Reply Last reply
                              0
                              • M MsmVc

                                Thanks for vital information and suggestion. I want to generate Combination of given String.Like this CString test="ABC", then generate like this AB AC AA BB BC BA CC CA CB If you have any type solution or suggestion then please help me.

                                E Offline
                                E Offline
                                Emilio Garavaglia
                                wrote on last edited by
                                #16

                                Ok, that's the problem. Now try to come to an algorithmic solution. That doesn't need to be C or C++, just pseudocode. Only when you find your algorithm looks meaningful, try to code it! Than: the problem is not well formed. Do you want only two char-s combination? Does the input string needs to be 3 char-s wide or can it be whatever? Be sure about that: you risk to produce a code that works on a very specific case, while looking for something more generic.

                                2 bugs found. > recompile ... 65534 bugs found. :doh:

                                M 1 Reply Last reply
                                0
                                • E Emilio Garavaglia

                                  Ok, that's the problem. Now try to come to an algorithmic solution. That doesn't need to be C or C++, just pseudocode. Only when you find your algorithm looks meaningful, try to code it! Than: the problem is not well formed. Do you want only two char-s combination? Does the input string needs to be 3 char-s wide or can it be whatever? Be sure about that: you risk to produce a code that works on a very specific case, while looking for something more generic.

                                  2 bugs found. > recompile ... 65534 bugs found. :doh:

                                  M Offline
                                  M Offline
                                  MsmVc
                                  wrote on last edited by
                                  #17

                                  yes you right.You have any idea about such type of algo because i havn't found algo.Please help me

                                  E 1 Reply Last reply
                                  0
                                  • M MsmVc

                                    yes you right.You have any idea about such type of algo because i havn't found algo.Please help me

                                    E Offline
                                    E Offline
                                    Emilio Garavaglia
                                    wrote on last edited by
                                    #18

                                    no, I cannot do your homework.

                                    2 bugs found. > recompile ... 65534 bugs found. :doh:

                                    M 1 Reply Last reply
                                    0
                                    • E Emilio Garavaglia

                                      no, I cannot do your homework.

                                      2 bugs found. > recompile ... 65534 bugs found. :doh:

                                      M Offline
                                      M Offline
                                      MsmVc
                                      wrote on last edited by
                                      #19

                                      you don't do my home work just i want to know url link or forum name.i know why you do my home work. thank

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups