- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
目前我将 argc、argv 和 temp 部分放入要传递的位置,当我编译时它没有返回任何错误,但是当我稍后在程序中调用该函数并向它传递一个 char 数组时。它返回堆栈转储。从我到目前为止所学到的知识来看,数组不能从函数传回,这就是我传递指针的原因。
int In2File(int argc, char *argv[], char *temp[] ){
if (argc == 2) { //open file
FILE *user_file;
user_file = fopen(argv[1], "r");
if (user_file == NULL) {
printf("No data was found.\nEnd(Error 1)");
exit(2);
}
else {
int g = 0;//temp counter to load
char c = 0;
while ((c = fgetc(user_file)) != EOF && g <= tmplng - 1) { //Used Fgetc instead of fgets because Fgetc allows me to read
*temp[g] = c; //until the end of the file and read each character. Even if there is an \n character.
g++; // The second g < tmplng-1 is used to make sure that the \0 can be placed into the array.
}
printf("%s\n", temp);
fclose(user_file);//Closed the txt file that was loaded by user in args(1)
printf("\nFile Loaded.\n");
}
}
else if (argc > 2) { // Will exit if arguments are greater than 2.
printf("Format: %s 'filename'", argv[0]);
exit(1);
}
else {
printf("File not provided. Enter information:\n");//If the user doesnt provide a file allow manual input.
fgets(*temp, tmplng, stdin);
}
}
In2File(argc,argv,temp);
有人知道我在这个函数上哪里出了问题吗?我读了一些类似的帖子,但它们是针对 C++ 和 Python 的。我还没有学过 C++,Python 与这个叫做 C 的野兽不同。
编辑:
const int tmplng = 1000; //The only variables needed
char temp[tmplng]; //
char temp2[tmplng]; //
printf("Starting....\n"); //Used for testing debugging.
最佳答案
函数的第三个参数与函数的预期不匹配。您传递的是 char []
(衰减为 char *
),而函数需要 char *[]
(等同于 char **
作为函数参数)。
第三个参数的定义与你打算如何使用它不匹配,它是一个字符数组。
去除参数上额外的间接级别,并相应地调整函数。
int In2File(int argc, char *argv[], char temp[] ){
...
while ((c = fgetc(user_file)) != EOF && g <= tmplng - 1) {
temp[g] = c;
g++;
}
关于创建文件到数组函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41004046/
我发现运行良好的代码片段可以轻松创建模块化 Delphi 应用程序。此代码适用于 Delphi 5 版本。 链接到片段 -> http://delphi.cjcsoft.net/viewthread.
我正在通过下面的代码以编程方式创建搜索索引。问题是插入设计文档后如何建立索引?或者它是第一次由 .search() 方法使用构建? var book_indexer = function(doc) {
我有一个非常小的项目,我想创建一个设置表单。做这个的最好方式是什么?简单地创建另一个带有复选框/文本框的 Windows 窗体并使用 Properties.Settings 类保存这些设置?它可能会起
我试图通过引用已经存在的 dm-linear、dm-snapshot、dm-cache 等来实现设备映射器目标。在我的实现中,我需要对某个扇区范围执行读/修改/写操作。由于设备映射器直接与块层对话,我
现在我有了一些空闲时间,我决定创建一个 Java 程序来将我的 XBee(即 zigbee)芯片连接到我的新 SmartThings 集线器。我找到了一个很好的教程,通过手动创建数据包来完成此操作(
我有一系列这种形式的静态实用方法: StringBuffer Util.doA(String arg0, String arg1, SomeEnum e); StringBuffer Util.do
我有一个 d3dDevice: ComPtrd3dDevice; 我在这里将它用于 dxgiDevice: ComPtr dxgiDevice2; HRESULT hr; hr
如何仅使用 css(样式)为我的 react-native View 组件背景创建此设计? 我希望 View 2 具有绿色背景,顶部有一条小曲线,与右上角的中心相交。 仅使用 borderRadius
我正在尝试创建一个有点动态的 html 类,它根据类末尾包含的数字设置宽度 %。注意:类名将始终以“gallery-item-”开头 示例:div.gallery-item-20 = 20% 宽度 我
基本上,我想要创 build 备方向值 alpha、beta 和 gamma 的可视化表示。到目前为止,我已经设法使用 innerHTML 以纯文本形式显示值,但我想为每个值创建一系列“条形图”。我根
我想用 Java 创 build 计二维码。 设计二维码可能包含图形形式的 Logo 。下面是此类设计代码的示例。 如何创建这样的二维码? 最佳答案 我刚刚找到了一个可以创建此类 QR 码的软件。 T
据我了解,SyncResponse 的有效负载是一个 Device 类型的数组。 我的问题是我无法创建在 SyncResponse - Payload - Device 内部定义的设备类型实例(无权访
我现在正在考虑如何创建类似以下事实的 android 应用程序... 起始页是 gridview,显示的列数将基于在设备屏幕分辨率上 当我点击 gridview 上的一项时,以下屏幕将根据设备分辨率显
我正在开发设备 onwer 应用程序,其中我必须使用 NFC 作为设备所有者安装我的应用程序,但是当我触摸两个设备并尝试安装应用程序时出现错误“由于校验和错误无法安装管理应用程序” 请告诉我哪里做错了
如何在不使用 mknod 或 MAKEDEV 的情况下(即通过使用动态注册)创 build 备文件。 最佳答案 假设你想在插入时动态分配一个主设备号给一个字符设备,使用: int alloc_chrd
我正在使用 .NET 为 IE 开发工具栏。目前,我使用 gacutil 插入我的 .NET 程序集,并使用 regasm 注册我的 COM 程序集。 我想为项目创建一个设置 (MSI),但我似乎无法
在为设置页面创建 Activity 后,我注意到 if (mCurrentValue !== value) 中的 mCurrentValue !== value 返回警告: Identity equa
我正在为用 C# 开发的软件开发设置表单。我正在研究不同的软件如何实现它们的设置表单。 在我遇到的大多数情况下,他们似乎在表单的左 Pane 中使用 Treeview,在右 Pane 中使用配置设置。
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 4 年前。 Improv
我正在尝试从 NodeJS 后端创建文档 ( https://firebase.google.com/docs/cloud-messaging/js/device-group ) 中所述的设备组,但我
我是一名优秀的程序员,十分优秀!