初めてC言語で自分の言語を教えたり、初めて(Mac)ターミナルを使う方法を学ぶための簡単なプログラムをCで書いています。 しかし、保存するためにscanf()に変数(ssn)を入力しようとすると、セグメント化エラーが発生します。変数をint型からint型に変更して問題を解決しようとしましたが(これは私が調べて、メモリの可用性/アクセスに関係していたと思っていましたが)役に立たないものでした。 私は本当にいくつかの指導に感謝します、ありがとう! 私のコードは以下の通りです:セグメンテーションフォールト11ターミナルでCを使用
/* A short example program from cs449 C Programming Text */
/* Section 4.13 */
/* Exercise 4-1 */
/**********************************************************
* *
* Write a program to print a name, SSN, and DOB *
* *
**********************************************************/
#include <stdio.h>
int main()
{
char name[20]; /* an array of char used to hold a name */
long ssn; /* an integer for holding a 9 dig ssn */
long dob; /* an integer for holding a date of birth */
/* for the name */
printf("Please enter your name: ");
scanf("%s", name);
/* for the SSN */
printf("Please enter your ssn: ");
scanf("%ld", ssn);
/* for the date of birth */
printf("Please enter your date of birth:\n");
printf("Ex. monthdayyear or 041293\n");
scanf("%ld", dob);
/* final print of user-entered information */
printf("You are %s born on %d and your SSN is %d", name, dob, ssn);
/* remember to always return 0 at the end of a main funct! */
return(0);
}
@BLUEPIXYのおかげでその間違いをキャッチするために! – Her
@BLUEPIXY、コメントに私の答えをコピーしてください:-) – ForceBru
@BLUEPIXYありがとう! – Her