I've been trying to figure out what I'm doing wrong in this block of code for a while now and still no luck. According to GDB, I'm receiving a SIGSEV, Segmentation Fault which means that I tried to access an invalid memory address.
Here I'm trying to find the length of the char pointer that is being passed
int getLength(char *start) {
int count = 0;
while(*start) {
count++;
start++;
}
return count;
}
Here is my full C file. I think it might be useful
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
int len1 = getLength(argv[1]);
int len2 = getLength(argv[2]);
if (argc != 3) {
fprintf(stderr, "Invalid number of items input.\n");
return 1;
}
if (len1!=len2) {
fprintf(stderr,"From and to are not the same size.\n");
return 1;
}
return 0;
}
int getLength(char *start) {
int count = 0;
while(*start) {
count++;
start++;
}
return count;
}
int duplicatesFrom(char *from) {
int i;
int j;
int len = getLength(from);
for(i=0;i<len;i++) {
for(j=0;j<len;j++) {
if (from[i]==from[j] && i!=j) {
return 1;
}
}
}
return 0;
}
startgetLength.