Results 1 to 5 of 5

Thread:

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jun:2020
    Location: Bulgaria
    Posts: 3

    ! , ? , . ! : Write a function void print_letter_of_my_strdup(char* s, unsigned short n), which prints "my_strdup[n] = L" where L is the letter or ASCII number of the letter at position n. For making a duplicate of the string use a function char *my_strdup(char *s) and for printing use function printf. Tip: Create a string to be duplicated in main() using char *s = (char *)malloc(5 * sizeof(char)); s[0] = 'a'; s[1] = 'b'; s[2] = 'c'; s[3] = 'd'; s[4] = 'e'; s[5] = 0;

    , :

    #include <iostream>
    using namespace std;

    char *my_strdup(char *s){
    _asm{
    push s
    call strlen
    add esp,4
    push eax
    call malloc;
    pop ecx
    mov ebx, s
    for:
    mov dl, [ebx + ecx]
    mov [eax+ecx], dl
    dec ecx
    cmp ecx, 0
    jge for
    }
    return s;
    }

    void print_letter_of_my_strdup(char* s, unsigned short n){

    }

    int main()
    {
    cout<<"Hello World";
    char *s=(char *)malloc(5 *sizeof(char));
    s[0]='a';
    s[1]='b';
    s[2]='c';
    s[3]='d';
    s[4]='e';
    s[5]=0;
    cout<<my_strdup(s)<<endl;
    return 0;
    }

    " which prints "my_strdup[n] = L" where L is the letter or ASCII number of the letter at position n" . , ASCII .
    , !!!

  2. #2
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448


    print_letter_of_my_strdup(s, 0) "my_strdup[0] = a"
    print_letter_of_my_strdup(s, 1) "my_strdup[1] = b"
    ...
    print_letter_of_my_strdup(s, 3) "my_strdup[3] = d"
    ...

    s. n- ( ).
    Last edited by anrieff; 3rd June 2020 at 23:55.
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  3. #3
    Registered User
    Join Date: Jun:2020
    Location: Bulgaria
    Posts: 3
    ! . ?

  4. #4
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    C

    Code:
    char* duplicate = my_strdup(s);
    printf("my_strdup[%d] = %c\n", n, duplicate[n]);
    - my_strdup.
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  5. #5
    Registered User
    Join Date: Jun:2020
    Location: Bulgaria
    Posts: 3
    !

Posting Permissions

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

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |