- Joined
- Dec 22, 2023
- Messages
- 34
- Reaction score
- 5
the negative indexes like "arr[-1]" so if arr is = {1,2,3,4}, it would print "3",but this cant be achieved in c,though i followed a tutorial that says to creata pointer pointing at the last position of the array,but i got a seg fault : (,
heres the code that a followed
heres my implementation,
heres the code that a followed
C:
int arr[5];
int* p = &arr[2];
int x = p[-2];
heres my implementation,
C:
#include <stdio.h>
#include <string.h>
int main() {
FILE *fptr;
fptr = fopen("addons.txt", "r");
int i;
char myString[100];
char my[100];
while (fgets(myString, 100, fptr)) {
char *size = &myString;
puts(size);
for (i = 0; i < 55; i++) {
myString[i] = *" ";
}
for (i = 57; i < 68; i++) {
size[i] = *" ";
}
strcat(my, myString);
}
fclose(fptr);
return 0;
}
Last edited: