从文件创建动态分配的字符串数组 [英] creating a dynamically allocated array of strings from a file

查看:64
本文介绍了从文件创建动态分配的字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何从文件中创建动态分配的字符串数组。我有一个字典,我想加载我的程序,以拼写检查。我无法决定是否最好使用字符串指针数组或实际单词数组。我也是C的新手,我对malloc还不太满意。任何帮助将不胜感激

解决方案


我想知道如何创建动态分配的字符串数组从文件。我有一个字典,我想加载我的程序,以拼写检查。我无法决定是否最好使用字符串指针数组或实际单词数组。我也是C的新手,我对malloc还不太满意。任何帮助将不胜感激



不幸的是,在C中没有这么简单的方法。我能想到的最简单的方法是使用双指针。

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | Wrap | 行号


感谢您的建议。所以,如果我要使用双指针,我会分别为行和列的malloc空间,或者你可以一起做吗?再次,我对malloc并不好。我也试图从已经在我的系统上的字典中读取这本字典。那么我如何根据这本词典中有多少单词来确定malloc空间的大小。我会去看看它,但我老板的字典可能会有所不同,因为他有一个旧版本的ubuntu。所以,我想知道能够把这本词典放在这个程序中也会有所帮助。



感谢您的建议。所以,如果我要使用双指针,我会分别为行和列的malloc空间,或者你可以一起做吗?再次,我对malloc并不好。我也试图从已经在我的系统上的字典中读取这本字典。那么我如何根据这本词典中有多少单词来确定malloc空间的大小。我会去看看它,但我老板的字典可能会有所不同,因为他有一个旧版本的ubuntu。所以,我想知道能够把这本字典放在这个程序中也会有所帮助。



我用指针不是很好但我相信你必须做这样的事情

展开 < span class =codeDivider> | 选择 | Wrap | Line编号

I was wondering how you would go about creating a dynamically allocated array of strings from a file. i have a dictionary that i want to load in my program in order to spell check. i cant decide if it is best to use an array of string pointers or an array of the actual words. also i am very new to C and really am not comfortable with malloc yet. any help would be greatly appreciated

解决方案

I was wondering how you would go about creating a dynamically allocated array of strings from a file. i have a dictionary that i want to load in my program in order to spell check. i cant decide if it is best to use an array of string pointers or an array of the actual words. also i am very new to C and really am not comfortable with malloc yet. any help would be greatly appreciated

Unfortunately in C there is no really easy way of doing this. The easiest way I can think of off the top of my head is to have a double pointer.

Expand|Select|Wrap|Line Numbers


thanks for the suggestion. so if i was going to use a double pointer would i malloc space for the rows and columns separately or can you do it together? again im not good with malloc. also i am trying to read this dictionary from one that is already on my system. so how would i determine how big to malloc space based on how many words are in this dictionary. i would just go look at it but my boss''s dictionary might be different because he has an older version of ubuntu. so ya i guess would also be helpful to know to be able to put this dictionary in this program.


thanks for the suggestion. so if i was going to use a double pointer would i malloc space for the rows and columns separately or can you do it together? again im not good with malloc. also i am trying to read this dictionary from one that is already on my system. so how would i determine how big to malloc space based on how many words are in this dictionary. i would just go look at it but my boss''s dictionary might be different because he has an older version of ubuntu. so ya i guess would also be helpful to know to be able to put this dictionary in this program.

I''m not that great with pointers but I believe you have to do something like this

Expand|Select|Wrap|Line Numbers


这篇关于从文件创建动态分配的字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆