Function Parameters & Pointers
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Function Parameters & Pointers

  1. #1
    Join Date
    Apr 2010
    Posts
    4

    Exclamation Function Parameters & Pointers

    This entire code works, but im having trouble with the pointers (which i dont understand 100%) In the code im taking the integers and holding them into a buffer (an array) so that i may use the int as a string so i can format the string with commas ie ###,###,###. I am getting the "passing arg 1 of "InsertComma" from incompatible pointer type"

    please help! and feel free to teach me the correct way to use pointers ;0

    its the char comma[64] and function insertcomma function im having problem with

    heres is the code:

    ////////////////////////////////////////////////////////////////////////

    #include "windows.h"
    #include "stdlib.h"
    #include "stdio.h"

    /* function prototype - appends commas to string */
    char InsertComma(char comma[]); <------ problem

    /* buffer to hold integers */
    char comma[64] = {0}; <------ problem

    int main()
    {

    int i;
    unsigned char data[512];
    DWORD dwBytesRead = 0;

    HANDLE hFile = NULL;

    hFile = CreateFile("\\\\.\\E:", /* drive to open */
    GENERIC_READ, /* allows drive read */
    FILE_SHARE_READ, /* shares read access */
    NULL, /* Security Descriptor */
    OPEN_EXISTING, /* declares creation */
    FILE_ATTRIBUTE_READONLY, /* access is read only */
    NULL); /* handle to template */

    if(hFile != NULL)
    {
    /* read the boot */
    if (!ReadFile(hFile, &data, 512, &dwBytesRead, NULL))
    {
    printf("Error in reading the specified drive!\n");
    }
    else
    {
    /* perform hexdump of boot information */
    for (i = 0; i<100; i++)
    printf("%d %X\n",i,data[i]);

    /* closes the handle */
    CloseHandle(hFile);

    /* turn the data into usable information for output*/
    int sb = *((int *)(data + 11)) & 0xFFFF;
    int cs = *((int *)(data + 13)) & 0xFF;
    int ns = *((int *)(data + 32)) & 0xFFFFFFFF;
    int nh = *((int *)(data + 26)) & 0xFFFF;
    int spf = *((int *)(data + 22)) & 0xFFFF;
    int rdcn = *((int *)(data + 44)) & 0xFFFFFFFF;
    int cncrd = *((int *)(data + 50)) & 0xFFFFFFFF;
    int tnob = *((int *)(data + 12)) & 0xFFFFFFFF; /* if anyone knows how to compute the total amount on the drive, pls let me know ;] */

    /* prints necessary output to screen */
    printf("\n ---- Disk Information ----");

    /* sprintf converts integer to string, holds data in (char data[]) */
    sprintf(comma, "%d", sb);
    printf("\nSector size (in bytes): "); InsertComma(&comma); <------ problem

    sprintf(comma, "%d", cs);
    printf("\nCluster size (in sectors): "); InsertComma(&comma); <------ problem

    sprintf(comma, "%d", ns);
    printf("\nTotal number of sectors: "); InsertComma(&comma); <------ problem

    sprintf(comma, "%d", nh);
    printf("\nTotal number of heads: "); InsertComma(&comma); <------ problem

    sprintf(comma, "%d", spf);
    printf("\nSectors per FAT: "); InsertComma(&comma); <------ problem

    sprintf(comma, "%d", rdcn);
    printf("\nRoot directory cluster number: "); InsertComma(&comma); <------ problem

    sprintf(comma, "%d", cncrd);
    printf("\nCluster number of the copy of the root directory: "); InsertComma(&comma);

    sprintf(comma, "%d", tnob);
    printf("\nTotal disk size in bytes: "); InsertComma(&comma);

    }
    }
    }

    char InsertComma(char comma[]) <------ problem
    {

    char *instring = comma; <------ problem
    char outstring[64];
    char *ptr, *optr;
    int i, length, commas;

    /* move ptr to end of instring */
    for ( ptr = instring; *ptr; ptr++ );

    /*calculate offset with commas*/
    length = ptr - instring;
    commas = ( length - 1 ) / 3;
    optr = outstring + length + commas;

    /*copy instring into outstring backwards inserting commas */
    *optr-- = *ptr--;
    for ( i = 1; ptr >= instring; i++ )
    {
    *optr-- = *ptr--;
    if ( ( i % 3 ) == 0 )
    *optr-- = ',';
    }

    /* show the result */
    printf ( "%s", outstring );
    }

  2. #2
    Join Date
    May 2007
    Posts
    1,546

    Re: Function Parameters & Pointers

    This is not C#, this is the wrong forum for this question.
    www.monotorrent.com For all your .NET bittorrent needs

    NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.

  3. #3
    Join Date
    Apr 2010
    Posts
    4

    Re: Function Parameters & Pointers

    how is this not C? im writing it in c and using cygwin gcc to compile it. I didnt see a gcc or cygwin category

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Function Parameters & Pointers

    You seem to be missing the '#' after the 'C'. This is a C# forum.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

  5. #5
    Join Date
    Apr 2010
    Posts
    4

    Re: Function Parameters & Pointers

    well ****! where is the 'C' forum?!

  6. #6
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Function Parameters & Pointers

    Just post your question in the C++ forum (actually, ask a mod to move this one) and let people now that you need an answer in strict C.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center