Int array

This is a discussion on Int array within the C Programming forums, part of the General Programming Boards category; I have trouble passing an array to my assembler program. The thing is - I have an array "srt" which ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    2

    Int array

    I have trouble passing an array to my assembler program. The thing is - I have an array "srt" which contains different characters for example "glammrr" and the assembler program stores into the array "set" only the differentiating characters - in this example it would be "glamr". And the array res counts the characters, in this example - "1,1,1,2,2". Now, I pass the res array as char * to the assembler program and everything's cool. But I have a problem with the int array.

    In a similar task a fellow student had - he didn't have an int array, but only a single integer, so he called function like this APAR(str, strlen(str), &res, set). I don't know what to do in my case. Any ideas?

    here's the C part.

    Code:
        #include <stdio.h>                                       
        int main(int argc,char *argv) {                         
            int res[8];                                     
            int i;                                               
            int l=8;                                             
            char srt[ ]="glammrr";                           
            char set[ ]="";                                   
            void APAR(const char *, const int, int *, char *);   
            APAR(srt, strlen(srt), res, set);     
             for (i=0; i<l; i++) {               
             printf("&#37;c",srt[i]);             
            }                                   
            printf("\n");                         
            for (i=0; i<l; i++) {               
             printf("%c", set[i]);             
            }                                   
             printf("\n");                         
             for (i=0; i<l; i++) {               
              printf("%d", res[i]);           
            }                                   
        }

    btw I tried passing an array pointer to the assembler program, but that didn't work because I don't know how the assembler program can handle a pointer.

    Also, I know the problem is here because the assembler program correctly produces the set array and it works correctly when is given a single number.
    Last edited by macho; 05-06-2008 at 08:33 AM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    First, a good tip: Put function declarations at global scope, not inside functions and name the arguments it takes appropriately, even in the declaration.

    Got a problem there? Take a look at:
    http://cpwiki.sourceforge.net/A_pointer_on_pointers
    It should answer your questions. Hopefully.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    2
    Thanks for the tips but I really don't need them because I'm not a C programmer, I have to finish my course in assembler programming.

    I know what a pointer is, I need to know what to do in this current situation...

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    The article tells you exactly what you must do in your C code and how pointers work.
    So you need to pass an array. The article tells how.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  3. problem with sorting
    By pinkpenguin in forum C Programming
    Replies: 2
    Last Post: 11-18-2005, 10:06 AM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 06:34 AM

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