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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • 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.