Start

Pracujemy tutaj nad ważniakiem 2

Informacje dla autorów

blad.c

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
 
#define ERROR  '@'
 
int palindrome_with_error(char* buf, size_t size) {
 
  char* tmp;
  size_t len;
  size_t i;
 
  buf[size] = '\0';
  tmp = (char*) malloc(size);
  if (tmp==NULL) return -1;
  len = strlen(buf);
  for (i = len; i>=0; i--) {
    if (buf[i] == ERROR) return -1;
    tmp[len-i]=buf[i];
  }
  int res = strcmp(buf, tmp);
  free(tmp);
  return res;
}
 
 
int main() {
  char a[10];
  strcpy(a, "aba");
  if (palindrome_with_error(a, 3))
    printf( "OK\n");
}
Subskrybuje zawartość