- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
<分区>
我收到段错误:11
在我运行菜单/命令后,我想将输入添加到列表中。试图弄清楚,但我无法提供任何帮助,感谢您
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <assert.h>
#define MAX_LENGTH 1023
//**********************************************************************
// Linked List Definitions
// Define your linked list node and pointer types
// here for use throughout the file.
//
// ADD STATEMENT(S) HERE
typedef struct contact
{
char familyName[MAX_LENGTH+1];
char firstName[MAX_LENGTH+1];
char address[MAX_LENGTH+1];
char phoneNumber[MAX_LENGTH+1];
struct contact *link;
//pointer to next node.
} contact;
//**********************************************************************
// Linked List Function Declarations
//
// Functions that modify the linked list.
// Declare your linked list functions here.
//
// ADD STATEMENT(S) HERE
//**********************************************************************
// Support Function Declarations
//
//Teacher's function:
void safegets (char s[], int arraySize); // gets without buffer overflow
void familyNameDuplicate (char familyName[]); // marker/tester friendly
void familyNameFound (char familyName[]); // functions to print
void familyNameNotFound (char familyName[]); // messages to user
void familyNameDeleted (char familyName[]);
void phoneNumberFound (char phoneNumber[]);
void phoneNumberNotFound (char phoneNumber[]);
void printPhoneBookEmpty (void);
void printPhoneBookTitle (void);
//My funcs:
void newContact (char familyName[], char firstName[], char address[], char phoneNumber[], contact **p);//want to modify something
void contactDel (contact **p, char familyName[]);
/* remove head */
contact *contact_search (contact *c, char familyName[]);
/* By Family Name*/
contact *phone_search (contact *c, char phoneNumber[]);
void print_all (contact *head);
void DelAll (contact **p);
//**********************************************************************
// Program-wide Constants
//
const char NULL_CHAR = '\0';
const char NEWLINE = '\n';
//**********************************************************************
// Main Program
//
int main (void)
{
contact *head=NULL;
contact *temp=NULL;
const char bannerString[]
= "Personal Phone Book Maintenance Program.\n\n";
const char commandList[]
= "Commands are I (insert), D (delete), S (search by name),\n"
" R (reverse search by phone #), P (print), Q (quit).\n";
// Declare linked list head.
// ADD STATEMENT(S) HERE TO DECLARE LINKED LIST HEAD.
// announce start of program
printf("%s",bannerString);
printf("%s",commandList);
char response;
char res[MAX_LENGTH+1];
char input[MAX_LENGTH+1];
char familyName[MAX_LENGTH+1];
char firstName[MAX_LENGTH+1];
char address[MAX_LENGTH+1];
char phoneNumber[MAX_LENGTH+1];
//to pass char arrays to insert function
do
{
printf("\nCommand?: ");
safegets(input,MAX_LENGTH+1);
// Response is first char entered by user.
// Convert to uppercase to simplify later comparisons.
response = toupper(input[0]);
if (response == 'I')
{
// Insert an phone book entry into the linked list.
// Maintain the list in alphabetical order by family name.
// ADD STATEMENT(S) HERE
// USE THE FOLLOWING PRINTF STATEMENTS WHEN PROMPTING FOR DATA:
printf(" family name: ");
fgets(familyName, MAX_LENGTH+1, stdin);
printf(" first name: ");
fgets(firstName, MAX_LENGTH+1, stdin);
printf(" address: ");
fgets(address, MAX_LENGTH+1, stdin);
printf(" phone number: ");
fgets(familyName, MAX_LENGTH+1, stdin);
newContact(familyName, firstName, address, phoneNumber, &head);
}
else if (response == 'D')
{
// Delete an phone book entry from the list.
// ADD STATEMENT(S) HERE
printf("\nEnter family name for entry to delete: ");
fgets(res,MAX_LENGTH,stdin);
contactDel(&head, res);
}
else if (response == 'S')
{
// Search for an phone book entry by family name.
printf("\nEnter family name to search for: ");
fgets(familyName, MAX_LENGTH, stdin);
temp=contact_search(head, familyName);
if (temp == NULL)
familyNameFound(res);
else
{
printf("%s\n%s\n%s\n%s\n\n", temp->familyName, temp->firstName, temp->address, temp->phoneNumber);
}
// ADD STATEMENT(S) HERE
}
else if (response == 'R')
{
// Search for an phone book entry by phone number.
//ADD STATEMENT(S) HERE
printf("\nEnter phone number to search for: ");
fgets(phoneNumber,MAX_LENGTH,stdin);
temp = phone_search(head, phoneNumber);
if (temp==NULL)
phoneNumberNotFound(phoneNumber);
else
{
phoneNumberFound(phoneNumber);
printf("\n%s\n%s\n%s\n%s\n", temp->familyName, temp->firstName, temp->address, temp->phoneNumber);
}
}
else if (response == 'P')
{
// Print the phone book.
// ADD STATEMENT(S) HERE
print_all(head);
}
else if (response == 'Q')
{
;// do nothing, we'll catch this below
}
else
{
// do this if no command matched ...
printf("\nInvalid command.\n%s\n",commandList);
}
} while (response != 'Q');
// Delete the whole phone book linked list.
// ADD STATEMENT(S) HERE
DelAll(&head);
// Print the linked list to confirm deletion.
// ADD STATEMENT(S) HERE
print_all (head);
return 0;
}
//**********************************************************************
// Support Function Definitions
// Function to get a line of input without overflowing target char array.
void safegets (char s[], int arraySize)
{
int i = 0, maxIndex = arraySize-1;
char c;
while (i < maxIndex && (c = getchar()) != NEWLINE)
{
s[i] = c;
i++;
}
s[i] = NULL_CHAR;
}
// Function to call when user is trying to insert a family name
// that is already in the book.
void familyNameDuplicate (char familyName[])
{
printf("\nAn entry for <%s> is already in the phone book!\n"
"New entry not entered.\n",familyName);
}
// Function to call when a family name was found in the phone book.
void familyNameFound (char familyName[])
{
printf("\nThe family name <%s> was found in the phone book.\n",
familyName);
}
// Function to call when a family name was not found in the phone book.
void familyNameNotFound (char familyName[])
{
printf("\nThe family name <%s> is not in the phone book.\n",
familyName);
}
// Function to call when a family name that is to be deleted
// was found in the phone book.
void familyNameDeleted (char familyName[])
{
printf("\nDeleting entry for family name <%s> from the phone book.\n",
familyName);
}
// Function to call when a phone number was found in the phone book.
void phoneNumberFound (char phoneNumber[])
{
printf("\nThe phone number <%s> was found in the phone book.\n",
phoneNumber);
}
// Function to call when a phone number was not found in the phone book.
void phoneNumberNotFound (char phoneNumber[])
{
printf("\nThe phone number <%s> is not in the phone book.\n",
phoneNumber);
}
// Function to call when printing an empty phone book.
void printPhoneBookEmpty (void)
{
printf("\nThe phone book is empty.\n");
}
// Function to call to print title when whole phone book being printed.
void printPhoneBookTitle (void)
{
printf("\nMy Personal Phone Book: \n");
}
//**********************************************************************
// Add your functions below this line.
// ADD STATEMENT(S) HERE
void newContact (char familyName[], char firstName[], char address[], char phoneNumber[], contact **head)
{
contact *testPtr=NULL;
testPtr = contact_search (*head, familyName);
if (strcmp(testPtr->familyName, familyName)==0)
{
familyNameDuplicate(familyName);
return;
}
else
testPtr = *head;
for ( ; strcmp(testPtr->familyName, familyName) < 0; testPtr = testPtr -> link)
;
contact *c = (contact *)malloc (sizeof(contact));//new node
strcpy(c->familyName, familyName);
strcpy(c->firstName, firstName);
strcpy(c->address, address);
strcpy(c->phoneNumber, phoneNumber);
if (head==NULL)
{
c->link = *head;
*head=c;
}
else
{
;
}
}
void contactDel (contact **p, char familyName[]) /* remove head */
{
contact *control=contact_search(*p, familyName);
if (control != NULL)
{
contact *n = control;
control = control -> link;
free(n);
}
}
void DelAll (contact **p)
{
if (*p != NULL)
{
contact *n = *p;
*p = (*p)->link;
free(n);
}
return;
}
contact *contact_search (contact *c, char familyName[]) /* By Family Name*/
{
while (c != NULL)
{
if (strcmp(c->familyName, familyName)==0)
{
return c;
}
c = c->link;
}
return NULL;
}
contact *phone_search (contact *c, char phoneNumber[])
{
while (c != NULL)
{
if (strcmp(c->phoneNumber, phoneNumber)==0)
{
return c;
}
c = c->link;
}
return NULL;
}
void print_all (contact *head)
{
if (head == NULL)
{
printPhoneBookEmpty();
}
else
{
printPhoneBookTitle();
while (head != NULL)
{
printf("%s\n%s\n%s\n%s\n\n", head->familyName, head->firstName, head->address, head->phoneNumber);
head = head->link;
}
}
}
程序应该将输入保存在列表中,然后在从用户那里获得选项后打印它们。等等,但为什么我会出现分段失败?
我已经使用 vue-cli 两个星期了,直到今天一切正常。我在本地建立这个项目。 https://drive.google.com/open?id=0BwGw1zyyKjW7S3RYWXRaX24tQ
您好,我正在尝试使用 python 库 pytesseract 从图像中提取文本。请找到代码: from PIL import Image from pytesseract import image_
我的错误 /usr/bin/ld: errno: TLS definition in /lib/libc.so.6 section .tbss mismatches non-TLS reference
我已经训练了一个模型,我正在尝试使用 predict函数但它返回以下错误。 Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]])
根据Microsoft DataConnectors的信息我想通过 this ODBC driver 创建一个从 PowerBi 到 PostgreSQL 的连接器使用直接查询。我重用了 Micros
我已经为 SoundManagement 创建了一个包,其中有一个扩展 MediaPlayer 的类。我希望全局控制这个变量。这是我的代码: package soundmanagement; impo
我在Heroku上部署了一个应用程序。我正在使用免费服务。 我经常收到以下错误消息。 PG::Error: ERROR: out of memory 如果刷新浏览器,就可以了。但是随后,它又随机发生
我正在运行 LAMP 服务器,这个 .htaccess 给我一个 500 错误。其作用是过滤关键字并重定向到相应的域名。 Options +FollowSymLinks RewriteEngine
我有两个驱动器 A 和 B。使用 python 脚本,我在“A”驱动器中创建一些文件,并运行 powerscript,该脚本以 1 秒的间隔将驱动器 A 中的所有文件复制到驱动器 B。 我在 powe
下面的函数一直返回这个错误信息。我认为可能是 double_precision 字段类型导致了这种情况,我尝试使用 CAST,但要么不是这样,要么我没有做对...帮助? 这是错误: ERROR: i
这个问题已经有答案了: Syntax error due to using a reserved word as a table or column name in MySQL (1 个回答) 已关闭
我的数据库有这个小问题。 我创建了一个表“articoli”,其中包含商品的品牌、型号和价格。 每篇文章都由一个 id (ID_ARTICOLO)` 定义,它是一个自动递增字段。 好吧,现在当我尝试插
我是新来的。我目前正在 DeVry 在线学习中级 C++ 编程。我们正在使用 C++ Primer Plus 这本书,到目前为止我一直做得很好。我的老师最近向我们扔了一个曲线球。我目前的任务是这样的:
这个问题在这里已经有了答案: What is an undefined reference/unresolved external symbol error and how do I fix it?
我的网站中有一段代码有问题;此错误仅发生在 Internet Explorer 7 中。 我没有在这里发布我所有的 HTML/CSS 标记,而是发布了网站的一个版本 here . 如您所见,我在列中有
如果尝试在 USB 设备上构建 node.js 应用程序时在我的树莓派上使用 npm 时遇到一些问题。 package.json 看起来像这样: { "name" : "node-todo",
在 Python 中,您有 None单例,在某些情况下表现得很奇怪: >>> a = None >>> type(a) >>> isinstance(a,None) Traceback (most
这是我的 build.gradle (Module:app) 文件: apply plugin: 'com.android.application' android { compileSdkV
我是 android 的新手,我的项目刚才编译和运行正常,但在我尝试实现抽屉导航后,它给了我这个错误 FAILURE: Build failed with an exception. What wen
谁能解释一下?我想我正在做一些非常愚蠢的事情,并且急切地等待着启蒙。 我得到这个输出: phpversion() == 7.2.25-1+0~20191128.32+debian8~1.gbp108
我是一名优秀的程序员,十分优秀!