0
I built the code below to separate only the last characters of a link (the last 11 to be exact). Until then everything works well, calculations are done normally, values also match. The problem is the time to give printf
in the String(vector) values, the problem is returned Segmentation fault (core dumped)
.
#include <stdio.h>
#include <string.h>
int main(){
char link[100];
int linkSize, calcLink;
scanf("%s", &link);
//lê o tamanho da string pra capturar os últimos caracteres
linkSize = strlen(link);
printf("\nTamanho da String: %i\n", linkSize);
calcLink = linkSize - 11;
printf("%s\n", link);
int i = calcLink;
while(i < linkSize){
printf("%s\n", link[i]);
++i;
}
return 0;
}
How to access the last memory addresses of my String link
and how to store these last characters in another string. I hope I was clear. I know it’s pretty basic, but as much as I looked, I couldn’t find an answer that could solve this particular case. I thank you for your understanding.
Interesting. Every time I explore this forum I am more surprised by how much knowledge we can acquire here. It’s nice to see experienced people are willing to help neophytes like me. Thank you for your answer, it was very helpful, I never really understood the operation of pointers, in fact I never really cared much. I see that this directly affects the development of a program. I thank you for your help!
– Henrique Marques
@I’m glad I could help. When programming in C, unless they are very simple things it is common to have to deal with pointers, and so it is important to know how to work with them.
– Isac