Populating a buffer from the return of a method fails... ANSI C -


the code have quite simple in 1 method have this:

// line has intellisense error: initialization {...} expected aggregate object char str[] = getbuffer(); // x 64 give 512 (sector sized buffer) ; 

the getbuffer metod this:

char * getbuffer(void) { int idx = 0; int offset = 0; char *buffer[512];  for(idx =0; idx < 64; idx ++) {             // line has itellisense error: "expected expression"     buffer[offset + idx] = {"e","r","a","s","e","d"," ", " "};      offset += 8; }  return *buffer; } 

any ideas what's wrong this? trying - populate buffer 512 bytes contain following string repeated: "erased " ansi c (not c++) , has been long since coded in ansi c - please , kind!

using visual studio 2012

edit 1 ok lots of things have been fixed guys - no full answer yet. str buffer holds 528 characters , not 512 , contains lot of erased expected ends

ýýýý««««««««îþîþ

any ideas this? , oh boy have great deal of pure c reading - have forgotten way much!

there problem buffer creation. you'd malloc such it's not reclaimed function invoke routine. second, can't assignment line encountered itellisense error. can use this:

#include "stdlib.h"  char * getbuffer(void) {     int = 0, idx = 0;     const char * cstr_init = "erased  ";     char *buffer = (char*)malloc(512);      (idx = 0; idx < 512; idx+=8) {         (i = 0; < 8; i++) {             buffer[idx+i] = cstr_init[i];         }     }      return buffer; } 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -