Help with C negative indexes

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

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:
Joined
Dec 22, 2023
Messages
34
Reaction score
5
my implementation is'int finished,its for downloading steam addons automaticaly,there is a addons.txt file that contains the link of every addon that i wanna install,what i wnat is to clean everything except the id of the file,then it wright it to the "my" variable,
 

Attachments

  • addons.txt
    787 bytes · Views: 19

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top