//Program is supossed to take in any length string but write string with size that user has given in
#include <cstdio>
#include <stdlib.h>
#include <malloc.h>
int main()
{
int size, i;
char *strings;
printf("How many letter has your string: ");
scanf("%d",&size);
strings = (char*)malloc(size +1); //+1 dla /0
printf("Type in string: ");
fgets(strings,size,stdin);
printf("%s",strings);
free(strings);
//scanf("%s",strings);
}
Program ma przyjmować string o dowolnym rozmiarze, a ma wypisać go w rozmiarze który został zaalokowany, tzn:
jaki dlugi jest string: 5
wprowadz string: tomawiecejniz5
twojstring: tomaw
Warunkiem jest użycie dynamicznej alokacji czyli malloc... Program kończy działanie po wprowadzeniu "size", ma to związek z zapchaniem bufora(?) i kompletnie nie wiem co robić... Wczytać to jakoś inaczej?