Jump to content
jonhhy

ANSWERED Trabalhar com Memória , crash

Recommended Posts

jonhhy
 #include <stdio.h>
 char * memset2 (char v[],char ch, int n);

 int main()
 {
    char *v = "PaP Programar";
    char ch = 'A';
    int n = 3; 
    
   
    puts("abc");
    printf("A string alterada é: %s \n",memset2(v,ch,n));
    puts("ghdfj");
 }

 char * memset2 (char v[],char ch, int n)
    {
        int i;
        for (i=0; i<n;i++)
            v[i] = ch;
        return v;
    }

output: http://prntscr.com/or6w63

Boa tarde Caríssimos  :),

o programa que estou a trabalhar crasha e não sei como resolver.

 

Share this post


Link to post
Share on other sites
PsySc0rpi0n

Se fizeres printf da variável 'v', o que mostra na linah de comandos?


Kurt Cobain - Grunge misses you

Nissan GT-R - beast killer

Share this post


Link to post
Share on other sites
HappyHippyHippo

a variável v contem um ponteiro para uma região de memória da qual não podes alterar (a string "PaP Programar")

quando vais tentar atribuir o caracter ch à posição v[i ], tens o problema que referes.

  • Vote 1

IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.