0

I always see this error

segmentation fault (core dumped) 

I am at the point of breaking can't seem to figure out what's wrong. Check50 is not working, says you are not connected to the internet, but Dropbox and Chrome work just fine. Any idea what's wrong. just gimme a hint not the answer.

#include <stdio.h>
#include <cs50.h>
#include <stdlib.h>
#include<string.h>
#include <ctype.h>

int main(int argc, string argv[])
{
  int k = atoi(argv[1]);

 //make sure you get an argc of 2 and only 2

  if (argc != 2)
  { 
  printf("you gave a wrong key please start again\n");
  return 1;
  }

[code snipped]

1
int main(int argc, string argv[]) 
{ 
    int k = atoi(argv[1]);

What happens if argv[1] doesn't exist? You will segfault.

Make sure you check whether it even exists before you try to assign its value to your variable. You are already checking argc, but you need to check beforehand.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .